- From: Lukas Tan <lukas.tan@cmis.csiro.au>
- Date: Thu, 13 Dec 2001 00:02:13 -0500 (EST)
- To: <xmlschema-dev@w3.org>
I suspect this is a fairly easy problem to solve, but am having no luck finding the solution, so: I want to have XML instances that contain elements (and possibly attributes) from different namespaces, vis: ---8<---------------------------------------------[stuff.xml] <?xml version="1.0" encoding="UTF-8"?> <stuff xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="stuff.xsd" xmlns:fruit="http://www.stuff.com/fruit" xmlns:vegies="http://www.stuff.com/vegies" xmlns:cereals="http://www.stuff.com/cereals"> <count>6</count> <fruit:apple>Granny Smith</fruit:apple> <fruit:orange>Valencia</fruit:orange> <vegies:carrot>Frozen</vegies:carrot> <vegies:beans>Also frozen</vegies:beans> <cereals:rice>2kg</cereals:rice> <cereals:bread>Toast</cereals:bread> </stuff> ---8<---------------------------------------------[stuff.xml] The schema this points to is stuff.xsd, below. This is where I suspect the problems are, as you cannot simply say <element name="fruit:apple" type="fruit:apple-type"> type things. Also, I think this is where the references to the other schemas (below) should be, but can't figure out how to include them here. I have no intention of using the namespaces, they're just there to keep the validator happy(er). ---8<---------------------------------------------[stuff.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" xmlns:vegies="http://www.stuff.com/vegies" xmlns:cereals="http://www.stuff.com/cereals"> <xsd:element name="stuff" type="stuff-type"/> <xsd:complexType name="stuff-type"> <xsd:all> <xsd:element name="count" type="xsd:nonNegativeInteger"/> <xsd:element name="fruit:apple" type="fruit:apple-type"/> <xsd:element name="fruit:orange" type="fruit:orange-type"/> <xsd:element name="vegies:carrot" type="vegies:carrot-type"/> <xsd:element name="vegies:beans" type="vegies:beans-type"/> <xsd:element name="cereals:rice" type="cereals:rice-type"/> <xsd:element name="cereals:bread" type="cereals:bread-type"/> </xsd:all> </xsd:complexType> </xsd:schema> ---8<---------------------------------------------[stuff.xsd] Following are the three "trivial" schemas for the "sub-namespaces": ---8<---------------------------------------------[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="unqualified" attributeFormDefault="unqualified"> <xsd:element name="apple" type="xsd:string"/> <xsd:element name="orange" type="xsd:string"/> </xsd:schema> ---8<---------------------------------------------[fruit.xsd] ---8<---------------------------------------------[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="unqualified" attributeFormDefault="unqualified"> <xsd:element name="carrot" type="xsd:string"/> <xsd:element name="beans" type="xsd:string"/> </xsd:schema> ---8<---------------------------------------------[vegies.xsd] ---8<---------------------------------------------[cereals.xsd] <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:cereals="http://www.stuff.com/cereals" targetNamespace="http://www.stuff.com/cereals" elementFormDefault="unqualified" attributeFormDefault="unqualified"> <xsd:element name="rice" type="xsd:string"/> <xsd:element name="bread" type="xsd:string"/> </xsd:schema> ---8<---------------------------------------------[cereals.xsd] As illuded to before, the problem centers around getting the XML instance and/or the stuff schema to recognise the three sub-namespaces and their schemas. The validator I'm using is Apache's Xerces (command line "java dom.Counter -n -v -s"), and the ultimate goal is for it to successfully validate the above with all files in the one directory on a local disk. All help appreciated. Thanks Lukas
Received on Wednesday, 19 December 2001 13:16:28 UTC