- From: <JKim@orbitz.com>
- Date: Tue, 4 Dec 2001 16:34:12 -0500 (EST)
- To: xmlschema-dev@w3.org
- Cc: Rahul.Srivastava@Sun.COM, Ravin.Shah@morganstanley.com, ychiu@orbitz.com, wshort@orbitz.com
Hi all, I am also having difficulties validating an xml document. I took the xml and xsd from this post and implemented some of the suggestions and have run into a few problems still. > 1. In your XMLSchema your default namespace ("") is different from > targetNamespace ("AnotherTestSpace"). So, the declaration: > > <xsd:complexType name="order"> > ... > </xsd:complexType> > > puts "order" in targetNamespace. But, when you refer it: > > <xsd:element name="shipOrder" type="order"/> > > it tries to find "order" in default namespace, as "order" is not prefixed, and > is unable to find it. This problem is everywhere in your schema. > > [Define a default namespace equal to targetNamespace OR define a namespace equal > to your targetNamespace and use that prefix when referring.] I have added a default namespace so that my xsd file now looks like this: <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="AnotherTestSpace" xmlns="AnotherTestSpace" elementFormDefault="qualified" > <xsd:element name="shipOrder" type="order"/> <xsd:complexType name="shipAddress"> <xsd:sequence> <xsd:element name="name" type="xsd:string"/> <xsd:element name="street" type="xsd:string"/> <xsd:element name="address" type="xsd:string"/> <xsd:element name="country" type="xsd:string"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="cdItem"> <xsd:sequence> <xsd:element name="title" type="xsd:string"/> <xsd:element name="quantity" type="xsd:positiveInteger"/> <xsd:element name="price" type="xsd:decimal"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="cdItems"> <xsd:sequence> <xsd:element name="item" type="cdItem"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="order"> <xsd:sequence> <xsd:element name="shipTo" type="shipAddress"/> <xsd:element name="items" type="cdItems"/> </xsd:sequence> </xsd:complexType> </xsd:schema> > > 2. You have not specified elementFormDefault attribute in your schema file. This > means it defaults to "unqualified". Therefore in your instance file, you need to > qualify *only* the global declarations. > > [Define a namespace equal to targetNamespace and qualify the global elements in > your xml file OR set elementFormDefault to qualified and define a default > namespace equal to targetNamespace in your instance file.] Here are my two attempts at modifying my xml file: Attempt 1: <?xml version="1.0" encoding="UTF-8"?> <foo:shipOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="AnotherTestSpace order_schema.xsd" xmlns:foo="AnotherTestSpace" > <shipTo> <name>Tove Svendson</name> <street>Ragnhildvei 2</street> <address>4000 Stavanger</address> etc... Attempt 2: <?xml version="1.0" encoding="UTF-8"?> <shipOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="AnotherTestSpace order_schema.xsd" xmlns="AnotherTestSpace" > <shipTo> <name>Tove Svendson</name> <street>Ragnhildvei 2</street> <address>4000 Stavanger</address> etc... In each case I get the following error: [Error] simple.xml:5:2: General Schema Error: Grammar with uri 2: AnotherTestSpace , can not found. In addition I still get the other errors from before: [Error] simple.xml:5:2: Element type "shipOrder" must be declared. [Error] simple.xml:6:9: Element type "shipTo" must be declared. etc... I am using Xerces 1.3.0's SAXCount parser. I verified that the xsd file is in fact named order_schema.xsd, and that it exists in the same directory as my xml file. I must be missing something fundamental which I don't know about. > > Hope this helps. > > Cheers, > Rahul. > > Sun Microsystems, Inc. > > > > From: Ravin Shah <Ravin.Shah@morganstanley.com> > > > > > > I am trying to validate some XML files and have come across many > > problems. Right now, I just want to get a sample program working that > > validates. I would appreciate any kind of help. > > > > I just want to validate an XML file against an XSD file. I have taken a > > very simple example but I get these results from the parser (The xml and > > xsd files are shown below): > > > > Error :order.xml:3:121: Schema error: ComplexType 'order': Invalid child > > 'element' in the complex type. > > Error :order.xml:3:121: Schema error: ComplexType 'shipAddress': Invalid > > child 'element' in the complex type. > > Error :order.xml:3:121: Schema error: ComplexType 'cdItem': Invalid > > child 'element' in the complex type. > > Error :order.xml:3:121: Schema error: ComplexType 'cdItems': Invalid > > child 'element' in the complex type. > > Error :order.xml:3:121: Element type "shipOrder" must be declared. > > Error :order.xml:4:11: Element type "shipTo" must be declared. > > Error :order.xml:5:11: Element type "name" must be declared. > > Error :order.xml:6:13: Element type "street" must be declared. > > Error :order.xml:7:14: Element type "address" must be declared. > > Error :order.xml:8:14: Element type "country" must be declared. > > Error :order.xml:10:10: Element type "items" must be declared. > > Error :order.xml:11:11: Element type "item" must be declared. > > Error :order.xml:12:14: Element type "title" must be declared. > > Error :order.xml:13:17: Element type "quantity" must be declared. > > Error :order.xml:14:14: Element type "price" must be declared. > > Error :order.xml:16:11: Element type "item" must be declared. > > Error :order.xml:17:14: Element type "title" must be declared. > > Error :order.xml:18:17: Element type "quantity" must be declared. > > Error :order.xml:19:14: Element type "price" must be declared. > > > > Here is my xml file: > > > > <?xml version="1.0" encoding="UTF-8"?> > > <shipOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > > xsi:schemaLocation="AnotherTestSpace order_schema.xsd"> > > <shipTo> > > <name>Tove Svendson</name> > > <street>Ragnhildvei 2</street> > > <address>4000 Stavanger</address> > > <country>Norway</country> > > </shipTo> > > <items> > > <item> > > <title>Empire Burlesque</title> > > <quantity>1</quantity> > > <price>10.90</price> > > </item> > > <item> > > <title>Hide your heart</title> > > <quantity>1</quantity> > > <price>9.90</price> > > </item> > > </items> > > </shipOrder> > > > > Here is my xsd file: > > > > <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" > > targetNamespace="AnotherTestSpace"> > > <xsd:element name="shipOrder" type="order"/> > > <xsd:complexType name="shipAddress"> > > <xsd:element name="name" type="xsd:string"/> > > <xsd:element name="street" type="xsd:string"/> > > <xsd:element name="address" type="xsd:string"/> > > <xsd:element name="country" type="xsd:string"/> > > </xsd:complexType> > > > > <xsd:complexType name="cdItem"> > > <xsd:element name="title" type="xsd:string"/> > > <xsd:element name="quantity" type="xsd:positiveInteger"/> > > <xsd:element name="price" type="xsd:decimal"/> > > </xsd:complexType> > > > > <xsd:complexType name="cdItems"> > > <xsd:element name="item" type="cdItem"/> > > </xsd:complexType> > > > > <xsd:complexType name="order"> > > <xsd:element name="shipTo" type="shipAddress"/> > > <xsd:element name="items" type="cdItems"/> > > </xsd:complexType> > > </xsd:schema> > > > > >
Received on Tuesday, 4 December 2001 17:02:28 UTC