[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] XSD elementFormDefault="unqualified" destroys the benefits ofnamespace m
Hi Folks, Recall that with XML Schemas you can specify that all elements in conforming instance documents must be namespace-qualified using: elementFormDefault="qualified" Or, you can specify that only top-level, global elements must be namespace-qualified using: elementFormDefault="unqualified" These can yield remarkably different instance documents. INSTANCE #1 Here is an example of an instance where the schema specifies "qualified": <?xml version="1.0"?> <c:camera xmlns:c="http://www.camera.org" xmlns:nikon="http://www.nikon.com" xmlns:olympus="http://www.olympus.com" xmlns:pentax="http://www.pentax.com"> <c:body> <nikon:description>Ergonomically designed casing for easy handling</nikon:description> </c:body> <c:lens> <olympus:zoom>300mm</olympus:zoom> <olympus:f-stop>1.2</olympus:f-stop> </c:lens> <c:manual_adapter> <pentax:speed>1/10,000 sec to 100 sec</pentax:speed> </c:manual_adapter> </c:camera> INSTANCE #2 Using the same schema, but specifying "unqualified," here is the instance: <?xml version="1.0"?> <c:camera xmlns:c="http://www.camera.org"> <body> <description>Ergonomically designed casing for easy handling </description> </body> <lens> <zoom>300mm</zoom> <f-stop>1.2</f-stop> </lens> <manual_adapter> <speed>1/10,000 sec to 100 sec</speed> </manual_adapter> </c:camera> BENEFITS OF NAMESPACES Namespaces modularize instance documents. They enable applications to perform module-specific processing. MODULES IN INSTANCE #1 In instance #1 the namespaces modularize the document. The document can be readily partitioned into these five modules: ------------------------------------------- <c:camera xmlns:c="http://www.camera.org"> <c:body> </c:body> <c:lens> </c:lens> <c:manual_adapter> </c:manual_adapter> </c:camera> ------------------------------------------- <nikon:description xmlns:nikon="http://www.nikon.com"> Ergonomically designed casing for easy handling </nikon:description> ------------------------------------------- <olympus:zoom xmlns:olympus="http://www.olympus.com"> 300mm </olympus:zoom> ------------------------------------------- <olympus:f-stop xmlns:olympus="http://www.olympus.com"> 1.2 </olympus:f-stop> ------------------------------------------- <pentax:speed xmlns:pentax="http://www.pentax.com"> 1/10,000 sec to 100 sec </pentax:speed> ------------------------------------------- MODULES IN INSTANCE #2 In instance #2 there is one namespace module and three no-namespace modules: ------------------------------------------- <c:camera xmlns:c="http://www.camera.org"> </c:camera> ------------------------------------------- <body> <description>Ergonomically designed casing for easy handling </description> </body> ------------------------------------------- <lens> <zoom>300mm</zoom> <f-stop>1.2</f-stop> </lens> ------------------------------------------- <manual_adapter> <speed>1/10,000 sec to 100 sec</speed> </manual_adapter> ------------------------------------------- PROBLEMS WITH INSTANCE #2 The no-namespace modules are comprised of multiple XML vocabularies. For example, in the lens module the <lens> element comes from the camera schema, whereas the <zoom> and <f-stop> elements come from the olympus schema. An application written for the olympus schema would not be able to process the lens module for these two reasons: a. The elements are not associated with the olympus namespace. Consider how the olympus application would behave upon encountering the lens module: "Is that <zoom> element really the element I know about, or is it somebody else's zoom element? b. The olympus application knows nothing about the <lens> element. RECOMMENDATION Don't use elementFormDefault="unqualified" in your XML Schemas. It destroys the modularity benefits provided by namespaces. Do you agree with this recommendation? /Roger
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] |
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
|