How do I 'expect' an element to have a namespace using XSD? At this point I receive an error saying: "Invalid content was found starting with element 'ns:person'. One of '{"":person}' is expected."
As you can see I define the name
attribute on the xs:element
: "p开发者_运维技巧erson". If I define "ns:person" as the name
then I get an error that the name is invalid aaarghh.
What am I missing here?
This is the XSD (ns.xsd):
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="peoples">
<xs:complexType>
<xs:sequence>
<xs:element name="person"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
This is the XML (peoples.xml):
<?xml version="1.0" encoding="ISO-8859-1"?>
<peoples xmlns:ns="url" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ns.xsd">
<ns:person>
<name>John</name>
</ns:person>
</peoples>
You need to include the complete XSD to help you. But from the error I see and the fact that you have included "xsi:noNamespaceSchemaLocation" in your XML instance document, the problem I see is that you defined your schema with no targetNamespace specified but you are qualifying person element with a namespace prefix. Just remove "ns:" at all places in your instance document and you are all good.
精彩评论