I built the following ('Person.xsd') XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema version="1.0" xmlns:xs="http://ift.tt/tphNwY"
targetNamespace="urn:person.com.test"
xmlns="urn:person.com.test">
<xs:element name="person" type="Person" />
<xs:complexType name="Person">
<xs:sequence>
<xs:sequence>
<xs:element name="first_name" type="xs:string" />
<xs:element name="last_name" type="xs:string"/>
</xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:schema>
And the following XML document ('Person.xml'):
<?xml version="1.0"?>
<person
xmlns="urn:person.com.test"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="urn:person.com.test person.xsd" >
<first_name>Joe</first_name>
<last_name>Bloggs</last_name>
</person>
But when I validate the XML (I'm using Netbeans 8.x , but other validators I have tried give very similar results); I get the following unhelpful message:
XML validation started.
Checking file:[...]/validator/src/main/resources/person.xml...
Referenced entity at "file:[...]/validator/src/main/resources/person.xsd".
cvc-complex-type.2.4.a: Invalid content was found starting with element 'first_name'. One of '{first_name}' is expected. [7]
XML validation finished.
Which seems to be saying - you are using the wrong element name 'first_name', it should be 'first_name' ?????
I suspect this has something to do with namespaces, but I can't work out what is wrong in particular here.....
No comments:
Post a Comment