XML Interviews Question page26,xml Interviews Guide,xml Interviews

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

XML Interviews Question page26,xml Interviews Guide,xml Interviews

XML Interviews Question page26

     

  1. How do I use XML namespaces with SAX 2.0?
    A: SAX 2.0 primarily supports XML namespaces through the following methods: * startElement and endElement in the ContentHandler interface return namespace names (URIs) and local names as well as qualified names. * getValue, getType, and getIndex in the Attributes interface can retrieve attribute information by namespace name (URI) and local name as well as by qualified name
       
  2. How do I use XML namespaces with DOM level 2?
    // Check the local name.
    // getNodeName() is a DOM level 1 method.
    if (elementNode.getNodeName().equals("SalesOrder"))
    {
    // Add new database record.
    }
    might become the following namespace-aware code:
    // Check the XML namespace name (URI).
    // getNamespaceURI() is a DOM level 2 method.
    String SALES_NS = "http://www.foo.com/ito/sales";
    if (elementNode.getNamespaceURI().equals(SALES_NS))
    {
    // Check the local name.
    // getLocalName() is a DOM level 2 method.
    if (elementNode.getLocalName().equals("SalesOrder"))
    {
    // Add new database record.
    }
    }
    Note that, unlike SAX 2.0, DOM level 2 treats xmlns attributes as normal attributes.
       
  3. Can an application process documents that use XML namespaces and documents that don't use XML namespaces?
    Yes.
    This is a common situation for generic applications, such as editors, browsers, and parsers, that are not wired to understand a particular XML language. Such applications simply treat all element type and attribute names as qualified names. Those names that are not mapped to an XML namespace -- that is, unprefixed element type names in the absence of a default XML namespace and unprefixed attribute names -- are simply processed as one-part names, such as by using a null XML namespace name (URI).
    Note that such applications must decide how to treat documents that do not conform to the XML namespaces recommendation. For example, what should the application do if an element type name contains a colon (thus implying the existence of a prefix), but there are no XML namespace declarations in the document? The application can choose to treat this as an error, or it can treat the document as one that does not use XML namespaces, ignore the "error", and continue processing.
         
  4. Can an application be both namespace-aware and namespace-unaware?
    Yes.
    However, there is generally no reason to do this. The reason is that most applications understand a particular XML language, such as one used to transfer sales orders between companies. If the element type and attribute names in the language belong to an XML namespace, the application must be namespace-aware; if not, the application must be namespace-unaware.
    For a few applications, being both namespace-aware and namespace-unaware makes sense. For example, a parser might choose to redefine validity in terms of universal names and have both namespace-aware and namespace-unaware validation modes. However, such applications are uncommon.
      
  5. What does a namespace-aware application do when it encounters an error?
    The XML namespaces recommendation does not specify what a namespace-aware application does when it encounters a document that does not conform to the recommendation. Therefore, the behavior is application-dependent. For example, the application could stop processing, post an error to a log and continue processing, or ignore the error.
    PART III: NAMES, PREFIXES, AND URIs
      
  6. What is a qualified name?
    A qualified name is a name of the following form. It consists of an optional prefix and colon, followed by the local part, which is sometimes known as a local name.
    prefix:local-part
    --OR--
    local-part
    For example, both of the following are qualified names. The first name has a prefix of serv; the second name does not have a prefix. For both names, the local part (local name) is Address.
    serv: Address
    Address In most circumstances, qualified names are mapped to universal names.
      
  7. What characters are allowed in a qualified name?
    The prefix can contain any character that is allowed in the Name [5] production in XML 1.0 except a colon. The same is true of the local name. Thus, there can be at most one colon in a qualified name -- the colon used to separate the prefix from the local name.
       
  8. Where can qualified names appear?
    Qualified names can appear anywhere an element type or attribute name can appear: in start and end tags, as the document element type, and in element type and attribute declarations in the DTD. 
    For example:
    <!DOCTYPE foo:A [
    <!ELEMENT foo:A (foo:B)>
    <!ATTLIST foo:A
    foo:C CDATA #IMPLIED>
    <!ELEMENT foo:B (#PCDATA)>
    ]>
    <foo:A xmlns:foo="http://www.foo.org/" foo:C="bar">
    <foo:B>abcd
    <foo:A>
    Qualified names cannot appear as entity names, notation names, or processing instruction targets.
      

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