• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

namespace

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The doc below i found in one of the old posts.. I am not clear as to why there are namespace declarations inside DTD..can anybody clearly expalin me this
<?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>
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i think in DTD there is not any Attribute Type whose name is "xmlns".i seem ur example is wrong.
give feedback.
cheers.
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please be kind enough to send us the url to the original thread.
Cheers,
Dan
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Actually above example document is perfectly valid. You can use ":" character for/within Element and Attribute name in DTD. So even though it looks like a name space declaration, it is not. One possible practical scenario for this would be :-
Company A has an XML application that uses DTD for validation. Company B has an XML application that uses Schema for validation. Now Company A receives the instance document from company B. Company A may develop a DTD like above to validate the incoming XML document. Probably this would be quickest/easy solution for company A to validate Company B's XML.
 
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it is not exactly that we are declaring namespaces inside the DTD. The only requirement is that name strings are valid XML names for elements and attributes. The DTD will be successfully validated against the xml for one small change as shown below -
<foo:A xmlns:foo="http://www.foo.org/">
<foo:B>abc</foo:B>
</foo:A>
We need to add the namespace declaration for the instance document as shown above. Otherwise, the validator complains that foo is an undeclared namespace.
I expected that we can even do away without adding the namespace declaration as xmlns:foo as the attribute "xmlns:foo" has a #FIXED value of "http://www.foo.org/". But the validator seem to be strictly looking as what is in there in the instance document.
I ran a little test with the java DOM parser code without supplying the "xmlns:foo" attribute as shown below -
<foo:A>
<foo:B>abc</foo:B>
</foo:A>
The parser successfully found this attribute from the DTD definition as it gave me the following output -
RootElement--foo:A
No. of children for root node 1
foo:A=null(ELEMENT_NODE)
ATTR::xmlns:foo=http://www.foo.org(ATTRIBUTE_NODE)
foo:B=null(ELEMENT_NODE)
#text=abc(TEXT_NODE)
The output is indented to show the correct depth of heirarchy.
This shows that it matters as to who is looking at the instance document, the validator or the parser. The validator doesn't seem to be caring about the #FIXED attribute and expects the namespace declaration for "foo". The parser is smart enough to resolve this.
Anyone please correct me for any mistakes.
Thanks.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, we all agree that the document is valid. But guys, xmlns:foo CDATA #FIXED "http://www.foo.org/" _is_ a namespace declaration. No doubt about it.
It will also be considered valid by a non-namespace aware parser, since foo:A and foo:B are valid XML names.
The validator at http://www.stg.brown.edu/cgi-bin/xmlvalid/xmlvalid.pl says the following -

warning (1391): namespace-declaring attribute inserted via DTD defaulting mechanisms (this is not good style): xmlns:foo


Merely – not a good style.
Cheers,
Dan
 
What a stench! Central nervous system shutting down. Save yourself tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic