- From: Lukas Tan <lukas.tan@cmis.csiro.au>
- Date: Wed, 19 Dec 2001 19:57:49 -0500 (EST)
- To: "Jeni Tennison" <jeni@jenitennison.com>
- Cc: <xmlschema-dev@w3.org>
----- Original Message ----- From: "Jeni Tennison" <jeni@jenitennison.com> To: "Lukas Tan" <lukas.tan@cmis.csiro.au> Cc: <xmlschema-dev@w3.org>; "Lukas Tan" <lukas.tan@csiro.au> Sent: Thursday, December 20, 2001 9:59 AM Subject: Re: Using multiple namespaces in an XML instance > Hi Lukas, > > > While this is not the ideal solution, as I do want to control > > exactly which elements from the other namespaces occur inside the > > "stuff" element (by some means such as using the "ref" attribute of > > the "xsd:element" element), it was the only way I could get the > > validator (Xerces) to accept the schemas. If I try the other (more > > desirable) approach: > [snip] > > Xerces says it "Cannot resolve the name 'fruit:apple' to a(n) elment > > declaration component." (typo and all). > > Strange. I tried using Xerces C++ 1.6.0 and XSV and it worked just > fine. If you can't get it working, post your schema and we can try to > work out what's going wrong. I've been doing some testing..... First of all, the XML is schanged somewhat, so that the "stuff" element contains "fruit" elements, and one of the "fruit" elements contains "vegies" elements. The XML: ========================================[stuff.xml] <?xml version="1.0" encoding="UTF-8"?> <stuff xmlns:fruit="http://www.stuff.com/fruit" xmlns:vegies="http://www.stuff.com/vegies" xmlns:cereals="http://www.stuff.com/cereals" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="stuff.xsd" xsi:schemaLocation="http://www.stuff.com/fruit fruit.xsd http://www.stuff.com/vegies vegies.xsd"> <count>4</count> <fruit:apple>Granny Smith</fruit:apple> <fruit:orange>Valencia</fruit:orange> <fruit:other> <vegies:carrot>Frozen</vegies:carrot> <vegies:beans>Also frozen</vegies:beans> </fruit:other> </stuff> ======================================== XML Schemas version 1: Wildcard references ========================================[stuff.xsd] <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="stuff" type="stuff-type"/> <xsd:complexType name="stuff-type"> <xsd:sequence> <xsd:element name="count" type="xsd:nonNegativeInteger"/> <xsd:any namespace="http://www.stuff.com/fruit" minOccurs="3" maxOccurs="3"/> </xsd:sequence> </xsd:complexType> </xsd:schema> ========================================[fruit.xsd] <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:fruit="http://www.stuff.com/fruit" targetNamespace="http://www.stuff.com/fruit" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xsd:element name="apple" type="xsd:string"/> <xsd:element name="orange" type="xsd:string"/> <xsd:element name="other"> <xsd:complexType> <xsd:sequence> <xsd:any namespace="http://www.stuff.com/vegies" minOccurs="2" maxOccurs="2"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> ========================================[vegies.xsd] <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:vegies="http://www.stuff.com/vegies" targetNamespace="http://www.stuff.com/vegies" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xsd:element name="carrot" type="xsd:string"/> <xsd:element name="beans" type="xsd:string"/> </xsd:schema> ======================================== Now, this validates happily in Xerces-J 2.0.0 beta3 and Xerces-J 1.4.4. If I duplicate an element such as the Valencia oranges (violating the maxOccurs), 2.0.0 picks it up, but 1.4.4 doesn't. XML Schemas version 2: Explicit references ========================================[stuff.xsd] <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:import namespace="http://www.stuff.com/fruit" schemaLocation="fruit.xsd"/> <xsd:element name="stuff" type="stuff-type"/> <xsd:complexType name="stuff-type"> <xsd:sequence> <xsd:element name="count" type="xsd:nonNegativeInteger"/> <xsd:element ref="fruit:apple" minOccurs="1" maxOccurs="1"/> <xsd:element ref="fruit:orange" minOccurs="1" maxOccurs="1"/> <xsd:element ref="fruit:other" minOccurs="1" maxOccurs="1"/> </xsd:sequence> </xsd:complexType> </xsd:schema> ========================================[fruit.xsd] <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:fruit="http://www.stuff.com/fruit" targetNamespace="http://www.stuff.com/fruit" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xsd:import namespace="http://www.stuff.com/vegies" schemaLocation="vegies.xsd"/> <xsd:element name="apple" type="xsd:string"/> <xsd:element name="orange" type="xsd:string"/> <xsd:element name="other"> <xsd:complexType> <xsd:sequence> <xsd:element ref="vegies:carrots" minOccurs="1" maxOccurs="1"/> <xsd:element ref="vegies:beans" minOccurs="1" maxOccurs="1"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> ========================================[vegies.xsd] <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:vegies="http://www.stuff.com/vegies" targetNamespace="http://www.stuff.com/vegies" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xsd:element name="carrot" type="xsd:string"/> <xsd:element name="beans" type="xsd:string"/> </xsd:schema> ======================================== This does not validate in Xerces-J 2.0.0 beta3, but does in Xerces-J 1.4.4. However, 1.4.4 (still) doesn't pick up maxOccurs violations. ========================================[Xerves output] D:\Lukas\Temp\XMLStuff2>java dom.Counter stuff.xml [Error] stuff.xml:11:41: src-resolve: Cannot resolve the name 'vegies:carrots' t o a(n) elment declaration component. [Error] stuff.xml:11:41: src-resolve: Cannot resolve the name 'vegies:beans' to a(n) elment declaration component. [Error] stuff.xml:11:41: src-resolve: Cannot resolve the name 'fruit:apple' to a (n) elment declaration component. [Error] stuff.xml:11:41: src-resolve: Cannot resolve the name 'fruit:orange' to a(n) elment declaration component. [Error] stuff.xml:11:41: src-resolve: Cannot resolve the name 'fruit:other' to a (n) elment declaration component. [Error] stuff.xml:11:41: src-resolve: Cannot resolve the name 'vegies:carrots' t o a(n) elment declaration component. [Error] stuff.xml:11:41: src-resolve: Cannot resolve the name 'vegies:beans' to a(n) elment declaration component. [Error] stuff.xml:14:15: cvc-complex-type.2.4.a: Invalid content starting with e lement 'fruit:apple'. The content must match '(((("":count),EMPTY),EMPTY),EMPTY) '. [Error] stuff.xml:16:15: cvc-complex-type.2.4.a: Invalid content starting with e lement 'fruit:other'. The content must match '(((("":count),EMPTY),EMPTY),EMPTY) '. [Error] stuff.xml:17:18: cvc-complex-type.2.4.a: Invalid content starting with e lement 'vegies:carrot'. The content must match '(EMPTY,EMPTY)'. stuff.xml: 271;0;0 ms (7 elems, 6 attrs, 0 spaces, 57 chars) ======================================== So, any thoughts? I don't have access to C++, so Xerces-C++ is not really an option. Thanks again. Lukas
Received on Thursday, 20 December 2001 10:25:56 UTC