XML Interviews Question page22,xml Interviews Guide,xml Interviews

This page discusses - XML Interviews Question page22,xml Interviews Guide,xml Interviews

XML Interviews Question page22,xml Interviews Guide,xml Interviews

XML Interviews Question page22

     

  1. From other XML namespaces?
    A: Yes and no.The answer to this question is yes in the sense that a qualified name in a content model can have a different prefix than the qualified name of the element type being declared. For example, the following is legal:
    <!ELEMENT google:A (bar:B, baz:C)>
    The answer to this question is no in the sense that XML namespace declarations do not apply to DTDs so the prefixes used in an element type declaration are technically meaningless. In particular, they do not specify that the name of a certain element type belongs to a certain namespace. Nevertheless, the ability to mix prefixes in this manner is crucial when: a) you have a document whose names come from multiple XML namespaces , and b) you want to construct that document in a way that is both valid and conforms to the XML namespaces recommendation .
       
  2. Can the attribute list of an element type contain attributes whose names come from other XML namespaces?
    Yes and no.
    For example, the following is legal:
    <!ATTLIST google:A
    bar:B CDATA #IMPLIED>
     
  3. How can I construct an XML document that is valid and conforms to the XML namespaces recommendation?
    In answering this question, it is important to remember that:
    * Validity is a concept defined in XML 1.0,
    * XML namespaces are layered on top of XML 1.0 , and
    * The XML namespaces recommendation does not redefine validity, such as in terms of universal names .
    Thus, validity is the same for a document that uses XML namespaces and one that doesn't. In particular, with respect to validity:
    * xmlns attributes are treated as attributes, not XML namespace declarations.
    * Qualified names are treated like other names. For example, in the name google:A, google is not treated as a namespace prefix, the colon is not treated as separating a prefix from a local name, and A is not treated as a local name. The name google:A is treated simply as the name google:A.
    Because of this, XML documents that you might expect to be valid are not. For example, the following document is not valid because the element type name A is not declared in the DTD, in spite of the fact both google:A and A share the universal name {http://www.google.org/}A:
    <?xml version="1.0" ?>
    <!DOCTYPE google:A [
    <!ELEMENT google:A EMPTY>
    <!ATTLIST google:A
    xmlns:google CDATA #FIXED "http://www.google.org/"
    xmlns CDATA #FIXED "http://www.google.org/">
    ]>
    <A/>
    Similarly, the following is not valid because the xmlns attribute is not declared in the DTD:
    <?xml version="1.0" ?>
    <!DOCTYPE A [
    <!ELEMENT A EMPTY>
    ]>
    <A xmlns="http://www.google.org/" />
    Furthermore, documents that you might expect to be invalid are valid. For example, the following document is valid but contains two definitions of the element type with the universal name {http://www.google.org/}A:
    <?xml version="1.0" ?>
    <!DOCTYPE google:A [
    <!ELEMENT google:A (bar:A)>
    <!ATTLIST google:A
    xmlns:google CDATA #FIXED "http://www.google.org/">
    <!ELEMENT bar:A (#PCDATA)>
    <!ATTLIST bar:A
    xmlns:bar CDATA #FIXED "http://www.google.org/">
    ]>
    <google:A>
    <bar:A>abcd</bar:A>
    </google:A>
    Finally, validity has nothing to do with correct usage of XML namespaces. For example, the following document is valid but does not conform to the XML namespaces recommendation because the google prefix is never declared:
    <?xml version="1.0" ?>
    <!DOCTYPE google:A [
    <!ELEMENT google:A EMPTY>
    ]>
    <google:A />
    Therefore, when constructing an XML document that uses XML namespaces, you need to do both of the following if you want the document to be valid:
    * Declare xmlns attributes in the DTD.
    * Use the same qualified names in the DTD and the body of the document.
    For example:
    <?xml version="1.0" ?>
    <!DOCTYPE google:A [
    <!ELEMENT google:A (google:B)
    <!ATTLIST google:A
    xmlns:google CDATA #FIXED "http://www.google.org/">
    <!ELEMENT google:B EMPTY>
    ]>
    <google:A>
    <google:B />
    </google:A>
    There is no requirement that the same prefix always be used for the same XML namespace. For example, the following is also valid:
    <?xml version="1.0" ?>
    <!DOCTYPE google:A [
    <!ELEMENT google:A (bar:B)>
    <!ATTLIST google:A
    xmlns:google CDATA #FIXED "http://www.google.org/">
    <!ELEMENT bar:B EMPTY>
    <!ATTLIST bar:B
    xmlns:bar CDATA #FIXED "http://www.google.org/">
    ]>
    <google:A>
    <bar:B />
    </google:A>
    However, documents that use multiple prefixes for the same XML namespace or the same prefix for multiple XML namespaces are confusing to read and thus prone to error. They also allow abuses such as defining an element type or attribute with a given universal name more than once, as was seen earlier. Therefore, a better set of guidelines for writing documents that are both valid and conform to the XML namespaces recommendation is:
    * Declare all xmlns attributes in the DTD.
    * Use the same qualified names in the DTD and the body of the document.
    * Use one prefix per XML namespace.
    * Do not use the same prefix for more than one XML namespace.
    * Use at most one default XML namespace.
    The latter three guidelines guarantee that prefixes are unique. This means that prefixes fulfill the role normally played by namespace names (URIs) -- uniquely identifying an XML namespace -- and that qualified names are equivalent to universal names, so a given universal name is always represented by the same qualified name. Unfortunately, this is contrary to the spirit of prefixes, which were designed for their flexibility. For a slightly better solution.

Tutorials

  1. XML Interviews Question
  2. XML Interviews Question page3
  3. XML Interviews Question page9
  4. XML Interviews Question page10
  5. XML Interviews Question page12
  6. XML Interviews Question page19
  7. XML Interviews Question page21
  8. XML Interviews Question page1,xml Interviews Guide,xml Interviews
  9. XML Interviews Question page11,xml Interviews Guide,xml Interviews
  10. XML Interviews Question page13,xml Interviews Guide,xml Interviews
  11. XML Interviews Question page14,xml Interviews Guide,xml Interviews
  12. XML Interviews Question page15,xml Interviews Guide,xml Interviews
  13. XML Interviews Question page16,xml Interviews Guide,xml Interviews
  14. XML Interviews Question page17,xml Interviews Guide,xml Interviews
  15. XML Interviews Question page18,xml Interviews Guide,xml Interviews
  16. XML Interviews Question page1,xml Interviews Guide,xml Interviews
  17. XML Interviews Question page21,xml Interviews Guide,xml Interviews
  18. XML Interviews Question page22,xml Interviews Guide,xml Interviews
  19. XML Interviews Question page23,xml Interviews Guide,xml Interviews
  20. XML Interviews Question page24,xml Interviews Guide,xml Interviews
  21. XML Interviews Question page25,xml Interviews Guide,xml Interviews
  22. XML Interviews Question page26,xml Interviews Guide,xml Interviews
  23. XML Interviews Question page27,xml Interviews Guide,xml Interviews
  24. XML Interviews Question page28,xml Interviews Guide,xml Interviews
  25. XML Interviews Question page29,xml Interviews Guide,xml Interviews
  26. XML Interviews Question page30,xml Interviews Guide,xml Interviews
  27. XML Interviews Question page1,xml Interviews Guide,xml Interviews
  28. XML Interviews Question page5,xml Interviews Guide,xml Interviews
  29. XML Interviews Question page6,xml Interviews Guide,xml Interviews
  30. XML Interviews Question page7,xml Interviews Guide,xml Interviews
  31. XML Interviews Question page8,xml Interviews Guide,xml Interviews