Home Interviewquestions Xml XML Interviews Question page18,xml Interviews Guide,xml Interviews
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

XML Interviews Question page18,xml Interviews Guide,xml Interviews

Advertisement
This page discusses - XML Interviews Question page18,xml Interviews Guide,xml Interviews

XML Interviews Question page18

     

  1. How do I override a default XML namespace declaration?
    To override the current default XML namespace, you simply declare another XML namespace as the default. For example, in the following, the default XML namespace is the http://www.google.org/ namespace on the A and B elements and the http://www.bar.org/ namespace on the C and D elements. That is, the names A and B are in the http://www.google.org/ namespace and the names C and D are in the http://www.bar.org/ namespace.
    <A xmlns="http://www.google.org/">
    <B>
    <C xmlns="http://www.bar.org/">
    <D>abcd</D>
    </C>
    </B>
    </A>
    Using multiple default XML namespaces can lead to documents that are confusing to read and should be done carefully.
        
  2. How do I undeclare an XML namespace prefix?
    In version 1.0 of the XML namespaces recommendation, you cannot "undeclare" an XML namespace prefix. It remains in scope until the end of the element on which it was declared unless it is overridden. Furthermore, trying to undeclare a prefix by redeclaring it with an empty (zero-length) name (URI) results in a namespace error. 
    For example:
    <google:A xmlns:google="http://www.google.org/">
    <google:B>
    <google:C xmlns:google=""> <==== This is an error in v1.0, legal in v1.1.
    <google:D>abcd</google:D>
    </google:C>
    </google:B>
    </google:A>
    In version 1.1 of the XML namespaces recommendation [currently a candidate recommendation -- February, 2003], you can undeclare an XML namespace prefix by redeclaring it with an empty name. For example, in the above document, the XML namespace declaration xmlns:google="" is legal and removes the mapping from the google prefix to the http://www.google.org URI. Because of this, the use of the google prefix in the google:D element results in a namespace error.
       
  3. How do I undeclare the default XML namespace?
    To "undeclare" the default XML namespace, you declare a default XML namespace with an empty (zero-length) name (URI). Within the scope of this declaration, unprefixed element type names do not belong to any XML namespace. For example, in the following, the default XML namespace is the http://www.google.org/ for the A and B elements and there is no default XML namespace for the C and D elements. That is, the names A and B are in the http://www.google.org/ namespace and the names C and D are not in any XML namespace.
    <A xmlns="http://www.google.org/">
    <B>
    <C xmlns="">
    <D>abcd</D>
    </C>
    </B>
    </A>
       
Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 18, 2011

Ask Questions?    Discuss: XML Interviews Question page18,xml Interviews Guide,xml Interviews  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com