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

DTD & Namespaces

 
Madhu VN
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following code throws an error : Reference to undeclared namespace prefix:test

<?xml version="1.0"?>
<!DOCTYPE test:firstname [
<!ELEMENT test:firstname (#PCDATA) >
<!ATTLIST test:firstname xmlns:test CDATA "namespace">
]>
<test:firstname>Content</test:firstname>

-----------------------------------------------------------------------------
The following code throws this error:
"Text is not allowed in this context according to DTD/Schema.Expecting:CDATA"

<?xml version="1.0"?>
<!DOCTYPE firstname [
<!ELEMENT firstname (CDATA) >
]>
<firstname><![CDATA[hithere>]]></firstname>

Could anyone let me know why this code is throwing the error?And what should be the change which has to be done in both the cases..
 
Tamer Badr
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the first one, the prefix test is a namespace that must be specified in the xml file, so if you don't have the DTD, you have to state the full url for the namespace like:
<test:firstname xmlns:test='urn:tests:test'>Content</test:firstname>
This if we will not validate the XML file with a DTD, but if we will use the DTD, then we will get another error because namespace declaration attribute in DTD is not supported, the only way is to validate the XML using XML Schema.

For the second one, there is no element type of CDATA, CDATA is a type of attributes only, it has to be (#PCDATA).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic