xml-validation

Validating xml nodes, not the entire document

爱⌒轻易说出口 提交于 2019-11-28 09:29:46
I'm working with some xml 'snippets' that form elements down the xml. I have the schema but I cannot validate these files because they are not complete xml documents. These snippets are wrapped with the necessary parent elements to form valid xml when they are used in other tools so I don't have much option in making them into valid xml or in changing the schema. Is it possible to validate an element, rather than the whole document? If not, what workarounds could be suggested? I'm working in C# with .NET 2.0 framework. I had a similar problem where I could only validate parts of my XML

XML XSD Schema - Enforce Unique Attribute Values in Schema

拈花ヽ惹草 提交于 2019-11-27 18:42:34
Lets say I have a schema that defines the following XML: <Values> <Add Key="Key1">Value 1</Add> <Add Key="Key2">Value 2</Add> <Add Key="Key3">Value 3</Add> <Add Key="Key4">Value 4</Add> </Values> I would like, at a schema level, to be able to enforce that the values for the Key attribute are unique, i.e. the example above is valid, but the following example would be invalid: <Values> <Add Key="Key1">Value 1</Add> <Add Key="Key2">Value 2</Add> <Add Key="Key2">Value 3</Add> <Add Key="Key3">Value 4</Add> </Values> Notice that there are two Add elements with a Key of Key2 For reference here is the

Getting started with XSD validation with .NET

半城伤御伤魂 提交于 2019-11-27 12:59:03
问题 Here is my first attempt at validating XML with XSD. The XML file to be validated: <?xml version="1.0" encoding="utf-8" ?> <config xmlns="Schemas" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="config.xsd"> <levelVariant> <filePath>SampleVariant</filePath> </levelVariant> <levelVariant> <filePath>LegendaryMode</filePath> </levelVariant> <levelVariant> <filePath>AmazingMode</filePath> </levelVariant> </config> The XSD, located in "Schemas/config.xsd"

Possible to validate xml against xsd using code at runtime?

早过忘川 提交于 2019-11-27 12:30:06
问题 I have xml files that I read in at runtime, is is possible to validate the xml against an xsd file at runtime? using c# 回答1: Try this: public void ValidateXmlDocument( XmlReader documentToValidate, string schemaPath) { XmlSchema schema; using (var schemaReader = XmlReader.Create(schemaPath)) { schema = XmlSchema.Read(schemaReader, ValidationEventHandler); } var schemas = new XmlSchemaSet(); schemas.Add(schema); var settings = new XmlReaderSettings(); settings.ValidationType = ValidationType

cvc-elt.1: Cannot find the declaration of element 'MyElement'

荒凉一梦 提交于 2019-11-27 12:21:22
I'm trying to validate a really simple xml using xsd, but for some reason I get this error. I'll really appreciate if someone can explain me why. XML File <?xml version="1.0" encoding="utf-8"?> <MyElement>A</MyElement> XSD File <?xml version="1.0" encoding="UTF-8"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/Test" xmlns:tns="http://www.example.org/Test" elementFormDefault="qualified"> <simpleType name="MyType"> <restriction base="string"></restriction> </simpleType> <element name="MyElement" type="tns:MyType"></element> </schema> Your schema is for

Validating SVG file in PHP with XMLReader

帅比萌擦擦* 提交于 2019-11-27 08:16:55
问题 I am validating a SVG document (which I believe to be valid) against the SVG spec. I'm using XMLReader in PHP, and would rather stick with that as I will be using XMLReader elsewhere; that said if there are other stream-based readers that will do this easier/better, do let me me know. OK, here's some code: // Set some values for the purpose of this example $this->path = '/Users/jon/Development/Personal/Visualised/master/test-assets/import-png.svg'; $xsdPath = '/Users/jon/Development/Personal

Why does XSD validation expect {element} with braces rather than just element?

我是研究僧i 提交于 2019-11-27 08:15:30
问题 When I try to validate the below XML against the below XSD I get the following error: cvc-complex-type.2.4.a: Invalid content was found starting with element >'personal'. One of '{personal} expected. XML <main xmlns = "http://www.example.com" xmlns:xsi = "https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "main.xsd"> <personal> <full-name>John Smith</full-name> <contact> <street-address>12345 Example Street</street-address> <city>Somewhere</city> <state>EX</state> <postal-code

Setting minOccurs and maxOccurs in XSD based on value of other XML field?

五迷三道 提交于 2019-11-27 07:27:36
问题 I have an XSD to validate an XML file. The structure is as follows: <root> <child> <size>2</size> <childElement>Element 1</childElement> <childElement>Element 2</childElement> </child> </root> The number of childElement s is dependent on the size provided i.e. if size was set as 3, not more than 3 childElement s can be added. I have tried using xs:alternative but it does not seem to work: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="root"> <xs:complexType> <xs

Server-Side XML Validation with CXF Webservice

若如初见. 提交于 2019-11-27 07:01:16
I'm working on an Apache CXF webservice (using JAX-WS, over SOAP). The service itself is pretty simple: receive a request, insert the request into a database, and return whether the insert was successful. I'd like to rely on XML validation to enforce a number of constraints on the request. So, my question. How do I return detailed validation errors to a client of my service? I've turned validation on server-side by configuring my endpoint. <jaxws:endpoint id="someEndpoint" implementor="#someImpl" address="/impl"> <jaxws:properties> <!-- This entry should- ideally- enable JAXB validation on the

XSD element substitution group example?

ぐ巨炮叔叔 提交于 2019-11-27 03:27:04
问题 I'd like to be able to specify single choice type for multiple extending types. For example, say we have the sea, in the sea there are many kinds of fishes. So in XML I will write: <Sea name="Atlantic Ocean"> <Tuna name="tuna1" /> <Carp name="carp1" /> <Carp name="carp2" /> <Tuna name="tuna2" /> <Salmon name="salmon1" /> </Sea> XSD <xs:complexType name="Fish"> </xs:complexType> <xs:complexType name="Salmon"> <xs:complexContent> <xs:extension base="Fish"> </xs:extension> </xs:complexContent> <