![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I'm fairly new to xsd. I'm validating xml against xsd using XmlReaderSettings. It looks like my xsd does not verify the element path: My schema definition allows for both OrderProperties and OrderPartners elements, however Partner can be specified only under OrderPartners. In other words, the correct path is OrderPartners/Partner, not OrderProperties/Partner. My xml contains OrderProperties/Partner ONLY and my xml validation code does not give me an error (I'm sure the code is working since it's giving me other errors such as invalid value for an attribute or missing element). I'm trying to figure out if there's something wrong with my validation code or the xsd. Before posting any code, I want to confirm what seems to me to be the case: 1. It is possible to make xsd to impose specific XPath. |
#3
| |||
| |||
|
|
Eve wrote: I'm fairly new to xsd. I'm validating xml against xsd using XmlReaderSettings. It looks like my xsd does not verify the element path: My schema definition allows for both OrderProperties and OrderPartners elements, however Partner can be specified only under OrderPartners. In other words, the correct path is OrderPartners/Partner, not OrderProperties/Partner. My xml contains OrderProperties/Partner ONLY and my xml validation code does not give me an error (I'm sure the code is working since it's giving me other errors such as invalid value for an attribute or missing element). I'm trying to figure out if there's something wrong with my validation code or the xsd. Before posting any code, I want to confirm what seems to me to be the case: 1. It is possible to make xsd to impose specific XPath. XSD schemas are not based on XPath (besides for key/unique constrainst). So I am not sure why you ask about "xsd to impose specific XPath". You can certainly specify however which child elements are allowed on a certain element simply using complexType and sequence for instance. You might want to post your XML and XSD so that we can better understand what your current problem is. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ |
#4
| |||
| |||
|
|
The xsd I'm using is rather complex, I didn't write it, it's third party and I prefer not to dig deep into it. I just need to get a general idea of how xsd works, specifically if it's possible for xsd to "prevent" xml from having an element in the wrong place, which according to what you wrote, Martin ("You can certainly specify which child elements are allowed on a certain element" - this is exactly what I mean when I say, "xsd to impose specific XPath"). If that's the case, why don't I get any errors if I specify a child element that is invalid? Again: OrderPartners/Partner is correct OrderProperties/Partner is not |
#5
| |||
| |||
|
|
Eve wrote: The xsd I'm using is rather complex, I didn't write it, it's third party and I prefer not to dig deep into it. I just need to get a general idea of how xsd works, specifically if it's possible for xsd to "prevent" xml from having an element in the wrong place, which according to what you wrote, Martin ("You can certainly specify which child elements are allowed on a certain element" - this is exactly what I mean when I say, "xsd to impose specific XPath"). If that's the case, why don't I get any errors if I specify a child element that is invalid? Again: OrderPartners/Partner is correct OrderProperties/Partner is not How do you validate exactly? Do you use an XML editor? If so which one? Or do you use an API, which one exactly? Have you tried a different editor or parser to check whether the validation problem is occuring there too? -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ |
#6
| |||
| |||
|
|
This is my validation code: |
#7
| |||
| |||
|
|
Eve wrote: This is my validation code: [snip] Your code is fine and I have used it with a simple XML document and schema and it outputs an error message. Here is the XML: ?xml version="1.0" encoding="utf-8" ? root OrderProperties Partner / /OrderProperties /root Here the schema: ?xml version="1.0" encoding="utf-8" ? xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xs:element name="root" xs:complexType xs:sequence xs:element name="OrderProperties" xs:complexType xs:sequence xs:element name="property" type="xs:string" / /xs:sequence /xs:complexType /xs:element /xs:sequence /xs:complexType /xs:element /xs:schema and here the output of your code: 1. Line 4, Position 6 "The element 'OrderProperties' has invalid child element 'Partner'. List of possible elements expected: 'property'." -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |