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

Can I use an attribute default in a DTD to declare an XML namespace?

Topic :
Feedback Request New QnA Print Email

Yes.
For example, the following uses the FIXED attribute xmlns:google on the A element type to associate the google prefix with the http://www.google.org/ namespace. The effect of this is that both A and B are in the http://www.google.org/ namespace.
<?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 (#PCDATA)>
]>
<!-- google prefix declared through default attribute. -->
<google:A>
<google:B>abc</google:B>
</google:A>

Importent:
You should be very careful about placing XML namespace declarations in external entities (external DTDs), as non-validating parsers are not required to read these. For example, suppose the preceding DTD was placed in an external entity (google.dtd) and that the document was processed by a non-validating parser that did not read google.dtd. This would result in a namespace error because the google prefix was never declared:
<?xml version="1.0" ?>
<!-- google.dtd might not be read by non-validating parsers. -->
<!DOCTYPE google:A SYSTEM "google.dtd">
<!-- google prefix not declared unless google.dtd is read. -->
<google:A>
<google:B>abc</google:B>
</google:A>

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