xsd - Why XML Schema example in primer fails to validate? -



xsd - Why XML Schema example in primer fails to validate? -

i looking @ po.xml illustration in xml schema primer:

<?xml version="1.0"?> <purchaseorder orderdate="1999-10-20" xmlns="http://www.example.com/po"> <shipto country="us"> <name>alice smith</name> <street>123 maple street</street> <city>mill valley</city> <state>ca</state> <zip>90952</zip> </shipto> <billto country="us"> <name>robert smith</name> <street>8 oak avenue</street> <city>old town</city> <state>pa</state> <zip>95819</zip> </billto> <comment>hurry, lawn going wild!</comment> <items> <item partnum="872-aa"> <productname>lawnmower</productname> <quantity>1</quantity> <usprice>148.95</usprice> <comment>confirm electric</comment> </item> <item partnum="926-aa"> <productname>baby monitor</productname> <quantity>1</quantity> <usprice>39.98</usprice> <shipdate>1999-05-21</shipdate> </item> </items> </purchaseorder>

when validate here fails validate using next schema:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:po="http://www.example.com/po" targetnamespace="http://www.example.com/po"> <xsd:annotation> <xsd:documentation xml:lang="en"> purchase order schema example.com. copyright 2000 example.com. rights reserved. </xsd:documentation> </xsd:annotation> <xsd:element name="purchaseorder" type="purchaseordertype"/> <xsd:element name="comment" type="xsd:string"/> <xsd:complextype name="purchaseordertype"> <xsd:sequence> <xsd:element name="shipto" type="usaddress"/> <xsd:element name="billto" type="usaddress"/> <xsd:element ref="comment" minoccurs="0"/> <xsd:element name="items" type="items"/> </xsd:sequence> <xsd:attribute name="orderdate" type="xsd:date"/> </xsd:complextype> <xsd:complextype name="usaddress"> <xsd:sequence> <xsd:element name="name" type="xsd:string"/> <xsd:element name="street" type="xsd:string"/> <xsd:element name="city" type="xsd:string"/> <xsd:element name="state" type="xsd:string"/> <xsd:element name="zip" type="xsd:decimal"/> </xsd:sequence> <xsd:attribute name="country" type="xsd:nmtoken" fixed="us"/> </xsd:complextype> <xsd:complextype name="items"> <xsd:sequence> <xsd:element name="item" minoccurs="0" maxoccurs="unbounded"> <xsd:complextype> <xsd:sequence> <xsd:element name="productname" type="xsd:string"/> <xsd:element name="quantity"> <xsd:simpletype> <xsd:restriction base="xsd:positiveinteger"> <xsd:maxexclusive value="100"/> </xsd:restriction> </xsd:simpletype> </xsd:element> <xsd:element name="usprice" type="xsd:decimal"/> <xsd:element ref="comment" minoccurs="0"/> <xsd:element name="shipdate" type="xsd:date" minoccurs="0"/> </xsd:sequence> <xsd:attribute name="partnum" type="sku" use="required"/> </xsd:complextype> </xsd:element> </xsd:sequence> </xsd:complextype> <!-- stock keeping unit, code identifying products --> <xsd:simpletype name="sku"> <xsd:restriction base="xsd:string"> <xsd:pattern value="\d{3}-[a-z]{2}"/> </xsd:restriction> </xsd:simpletype> </xsd:schema>

with next error:

src-resolve.4.1: error resolving component 'purchaseordertype'. detected 'purchaseordertype' has no namespace, components no target namespace not referenceable schema document 'null'. if 'purchaseordertype' intended have namespace, perhaps prefix needs provided. if intended 'purchaseordertype' has no namespace, 'import' without "namespace" attribute should added 'null'.

similar happens if run xmllint --schema po.xsd po.xml:

po.xsd:10: element element: schemas parser error : element '{http://www.w3.org/2001/xmlschema}element', attribute 'type': references schema components in no namespace not allowed, since not indicated import statement.

(i added xmlns:po="http://www.example.com/po" targetnamespace="http://www.example.com/po" root element in schema found in primer in hope create work, no luck.)

to clear, schema , instance document using modified variants of found in xsd primer. have modified them adding namespace, , have done incorrectly. example, have changed purchaseordertype in namespace, have not changed reference purchaseordertype reflect change; needs like

<xsd:element name="purchaseorder" type="po:purchaseordertype"/>

where namespace prefix po bound target namespace of schema. same applies other component references within schema.

xml xsd

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -