Reputation: 105063
This is the schema in my.xsd
:
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'
xmlns:p='some-namespace' targetNamespace='some-namespace'>
<xs:element name='root' type='p:main'/>
<xs:complexType name='main'>
<xs:sequence>
<xs:element name='alpha' type='xs:string' />
</xs:sequence>
</xs:complexType>
</xs:schema>
This is the XML document I'm validating against it:
<root xmlns='some-namespace'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='some-namespace my.xsd'>
<alpha>xxx</alpha>
</root>
SAX parser says:
"Invalid content was found starting with element 'alpha'. One of
'{alpha}' is expected."
What's wrong?
Upvotes: 3
Views: 125
Reputation: 4456
You have to add
elementFormDefault="qualified"
in your schema definition. It would also be a good idea not to use relative namespace, i.e. use something like this:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:p="http://some-namespace" targetNamespace="http://some-namespace"
elementFormDefault="qualified">
Upvotes: 4