JavaBeat Certifications Certifications Kits Articles Interview Questions OCAJP 7 OCPJP 5 OCPJP 6 OCEJWCD 6 SCBCD 5.0 SCEA SCJA

When should I use the default XML namespace instead of prefixes?

Topic :
Feedback Request New QnA Print Email

This is purely a matter of choice, although your choice may affect the readability of the document. When elements whose names all belong to a single XML namespace are grouped together, using a default XML namespace might make the document more readable.
For example:
<!-- A, B, C, and G are in the http://www.google.org/ namespace. -->
<A xmlns="http://www.google.org/">
<B>abcd</B>
<C>efgh</C>
<!-- D, E, and F are in the http://www.bar.org/ namespace. -->
<D xmlns="http://www.bar.org/">
<E>1234</E>
<F>5678</F>
</D>
<!-- Remember! G is in the http://www.google.org/ namespace. -->
<G>ijkl</G>
</A>

When elements whose names are in multiple XML namespaces are interspersed, default XML namespaces definitely make a document more difficult to read and prefixes should be used instead.
For example:
<A xmlns="http://www.google.org/">
<B xmlns="http://www.bar.org/">abcd</B>
<C xmlns="http://www.google.org/">efgh</C>
<D xmlns="http://www.bar.org/">
<E xmlns="http://www.google.org/">1234</E>
<F xmlns="http://www.bar.org/">5678</F>
</D>
<G xmlns="http://www.google.org/">ijkl</G>
</A>
In some cases, default namespaces can be processed faster than namespace prefixes, but the difference is certain to be negligible in comparison to total processing time.

Topic :
Feedback Request New QnA Print Email

All api java java 6.0 java 7.0 jdbc jsp servlet ejb jndi jms ejb 3.0 j2ee jee 5.0 jee 6.0 jsf struts spring Hibernate ajax JBoss Seam netbeans eclipse ant xml maven dojo junit javafx j2me log4j ESB JBoss Apache Quartz scjp mysql oracle gwt openjpa jmx yui google-guice android JBoss scwcd 5.0 scjp 1.5 scjp 1.6 scja scbcd 5.0

javabeat | advertise | about us | contact | useful resources
Copyright (2004 - 2013), JavaBeat