[xml] XML schema support
- From: "Robin Ehrlich" <REhrlich ubiqinc com>
- To: <xml gnome org>
- Subject: [xml] XML schema support
- Date: Wed, 21 May 2003 16:06:01 -0500
I am trying to get my application to use schema validation and as a test I
used "testSchemas" against a simple XML file, but I get all sorts of errors.
Is basic schema support available in v2.5.4?
**** Here is my schema:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://tempuri.org/po.xsd"
xmlns="http:tempuri.org/po.xsd" elementFormDefault="qualified">
<xs:annotation>
<xs:documentation xml:lang="en">
Purchase order schema for Example.com.
Copyright 2000 Example.com. All rights reserved.
</xs:documentation>
</xs:annotation>
<xs:element name="purchaseOrder" type="PurchaseOrderType"/>
<xs:element name="comment" type="xs:string"/>
<xs:complexType name="PurchaseOrderType">
<xs:sequence>
<xs:element name="shipTo" type="USAddress"/>
<xs:element name="billTo" type="USAddress"/>
<xs:element ref="comment" minOccurs="0"/>
<xs:element name="items" type="Items"/>
</xs:sequence>
<xs:attribute name="orderDate" type="xs:date"/>
</xs:complexType>
<xs:complexType name="USAddress">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="street" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="state" type="xs:string"/>
<xs:element name="zip" type="xs:decimal"/>
</xs:sequence>
<xs:attribute name="country" type="xs:NMTOKEN"
fixed="US"/>
</xs:complexType>
<xs:complexType name="Items">
<xs:sequence>
<xs:element name="item" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="productName" type="xs:string"/>
<xs:element name="quantity">
<xs:simpleType>
<xs:restriction base="xs:positiveInteger">
<xs:maxExclusive value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="USPrice" type="xs:decimal"/>
<xs:element ref="comment" minOccurs="0"/>
<xs:element name="shipDate" type="xs:date" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="partNum" type="SKU" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<!-- Stock Keeping Unit, a code for identifying products -->
<xs:simpleType name="SKU">
<xs:restriction base="xs:string">
<xs:pattern value="\d{3}-[A-Z]{2}"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
*** and the XML:
<?xml version="1.0"?>
<purchaseOrder xmlns="http://tempuri.org/po.xsd" orderDate="1999-10-20">
<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, my lawn is going wild!</comment>
<items>
<item partNum="872-AA">
<productName>Lawnmower</productName>
<quantity>1</quantity>
<USPrice>148.95</USPrice>
<comment>Confirm this is 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>
*** and finally the errors from testSchema (v2.5.4)
C:\TEMP>e:testSchemas po.xsd po.xml
Unable to lookup type USAddressSchemas: element shipTo type USAddress not
found
Unable to lookup type USAddressSchemas: element billTo type USAddress not
found
Schemas: element anonelem2 ref to comment not found
Unable to lookup type ItemsSchemas: element items type Items not found
Schemas: element anonelem9 ref to comment not found
Unable to lookup type PurchaseOrderTypeSchemas: element purchaseOrder type
Purch
aseOrderType not found
Type of sequence 1 : po.xsd:15 :elements
Type of sequence 4 : po.xsd:37 :elements
Type of sequence 3 : po.xsd:25 :elements
Type of sequence 1 : po.xsd:15 :elements
Type of PurchaseOrderType : po.xsd:14 :elements
Type of simpletype7 : po.xsd:43 :simple
Type of sequence 3 : po.xsd:25 :elements
Type of USAddress : po.xsd:24 :elements
Type of restriction 8 : po.xsd:44 :empty
Type of sequence 4 : po.xsd:37 :elements
Type of Items : po.xsd:36 :elements
Type of sequence 6 : po.xsd:40 :elements
Type of anontype5 : po.xsd:39 :elements
Type of sequence 6 : po.xsd:40 :elements
Type of restriction 10 : po.xsd:61 :empty
Type of SKU : po.xsd:60 :simple
Building content model for item
Unable to lookup type SKUSchemas: attribute partNum type SKU not found
Element purchaseOrder has no type
po.xml fails to validate
Thanks for any help,
Robin
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]