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?
You have to add
elementFormDefault="qualified"
in your schema definition. It would also be a good idea not to use relative namespace, ie 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">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.