• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DTD & Namespaces

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
reply
    Bookmark Topic Watch Topic
  • New Topic