[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] XML Schemas and Namespaces
Hi Folks, I have a couple of questions with regards to the use of namespaces in XML Schemas. 1. As has been recently discussed, the method for an XML instance document to indicate the XML Schema that it conforms to is with the schemaLocation attribute. For example: <?xml version="1.0"?> <BookCatalogue xmlns:xsi="http://www.w3.org/1999/XMLSchema/instance" xsi:schemaLocation= "http://www.somewhere.org/BookCatalogue http://www.somewhere.org/BookCatalogue/BookCatalogue.xsd"> ... </BookCatalogue> At the root element (BookCatalogue) of this XML instance document I am using schemaLocation to indicate the XML Schema that it conforms to. The problem is this: when I defined BookCatalogue (in BookCatalogue.xsd) I didn't define any attributes for it. I certainly didn't define xmlns:xsi nor xsi:schmemaLocation as attributes. Thus, this XML instance document is invalid, right? The nice thing about DOCTYPE was that it separated the mechanism for declaring the associated schema (i.e., the DTD) from the information items (i.e., the elements). With schemaLocation the mechanism for declaring the associated schema is intertwined with the information items. Thus, it seems that when an XML Schema is written the author must try to anticipate how instance documents will use it and add in xmlns:xsi and xsi:schemaLocation attributes to the elements being defined in the schema. For my example, I would need to define BookCatalogue as: <element name="BookCatalogue"> <type> <element ref="cat:Book" minOccurs="0" maxOccurs="*"/> <attribute name="xmlns:xsi" type="URI"/> <attribute name="xsi:schemaLocation" type="string"/> </type> </element> I must be misunderstanding something fundamental. This is obviously ridiculous. 2. My second question has to do with referencing elements within an XML Schema. Consider this schema: <?xml version="1.0"?> <!DOCTYPE schema SYSTEM "xml-schema.dtd"[ <!ATTLIST schema xmlns:cat CDATA #IMPLIED> ]> <schema xmlns="http://www.w3.org/1999/XMLSchema" targetNamespace="http://www.somewhere.org/BookCatalogue" xmlns:cat="http://www.somewhere.org/BookCatalogue"> <element name="BookCatalogue"> <type> <element ref="cat:Book" minOccurs="0" maxOccurs="*"/> </type> </element> <element name="Book"> <type> <element ref="cat:Title"/> <element ref="cat:Author"/> <element ref="cat:Date"/> <element ref="cat:ISBN"/> <element ref="cat:Publisher"/> </type> </element> <element name="Title" type="string"/> <element name="Author" type="string"/> <element name="Date" type="date"/> <element name="ISBN" type="string"/> <element name="Publisher" type="string"/> </schema> Note that we define the Book element and in the BookCatalogue element it is referenced using cat:Book <element name="BookCatalogue"> <type> <element ref="cat:Book" minOccurs="0" maxOccurs="*"/> </type> </element> My understanding is that the reason for prefixing Book with cat: is to indicate "the Book element that we are referencing comes from the cat: namespace". The cat: namespace is defined at the top of the schema to be the same as the targetNamespace. Thus, the cat: namespace refers to this schema document. Here's my question: it appears to me that namespaces are being used here to "point" to things. In this case, cat: is "pointing" to the current document (the XML Schema). Isn't this a violation of the namespace spec, which says that there is no guarantee that there is anything at the URI referenced by a namespace? /Roger xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@i... Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1 To unsubscribe, mailto:majordomo@i... the following message; unsubscribe xml-dev To subscribe to the digests, mailto:majordomo@i... the following message; subscribe xml-dev-digest List coordinator, Henry Rzepa (mailto:rzepa@i...)
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|