Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Tong Chen
Ranch Hand
Posts: 1011
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the XML Namespace FAQ, the answer is YES.
An example is given:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo:A [
<!ELEMENT foo:A (foo:B)>
<!ATTLIST foo:A xmlns:foo CDATA #FIXED "http://www.foo.org/">
<!ELEMENT foo:B (#PCDATA)>
]>
<!-- foo prefix declared through default attribute. -->
<foo:A>
<foo:B>abc</foo:B>
</foo:A>
However, the validator says: the namespace prefix "foo" was not declared.
Anyone can help clarify this? Thanks!!
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
foo is declared as a fixed namespace for A elements. It is not declared for B elements. So, I agree with the validator. However, XML Spy disagrees with the validator and me. It concludes that the document is valid.
Beats me!
Dan
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, you don’t need to associate a prefix to the namespace, you can do the following –
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE A [
<!ELEMENT A (B)>
<!ATTLIST A xmlns CDATA #FIXED "http://www.foo.org/">
<!ELEMENT B (#PCDATA)>
<!ATTLIST B xmlns CDATA #FIXED "http://www.foo.org/">
]>
<A>
<B>abc</B>
</A>
Cheers,
Dan
 
Gobiraj Vadivelrajan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it a sequence problem that foo ns is declared in line 4 and it is getting used in line 2 of the DTD
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic