Solved

Very basic XML/DTD CDATA question

Posted on 2004-08-19
2
940 Views
Last Modified: 2013-11-19
I don't want the text in the testchild node to be parsed.

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE test [
  <!ELEMENT test (testchild)>
  <!ELEMENT testchild (#CDATA)>
]>
<test>
<testchild>test once more.</testchild>
</test>

This throws an error when I try to view the file in IE 6.

The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------
Content model is invalid. Error processing resource 'file:///C:/Documents and Settings/e58012/My Documents/test.xml'. Line 4, Position 24
  <!ELEMENT testchild (#CDATA)>

According to this site, though, CDATA is legal for a DTD element type.  http://www.thescarms.com/XML/DTDTutorial.asp

Here's their example:

<?xml version="1.0"?>
<!DOCTYPE message [
  <!ELEMENT message (to,from,subject,text)>
  <!ELEMENT to         (#CDATA)>
  <!ELEMENT from      (#CDATA)>
  <!ELEMENT subject (#CDATA)>
  <!ELEMENT text     (#CDATA)>
]>
<message>
  <to>Dave</to>
  <from>Susan</from>
  <subject>Reminder</subject>
  <text>Don't forget to buy milk on the way home.</text>
</message>

Am I missing something?
0
Comment
Question by:slacksoft
2 Comments
 
LVL 22

Accepted Solution

by:
NovaDenizen earned 75 total points
ID: 11843384
That site is just wrong. :)

You can't have a '#CDATA' content type in an <!ELEMENT> tag.  '#PCDATA' is fine, though.

However, using '#PCDATA' won't stop you from using CDATA blocks in your data, like:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE test [
  <!ELEMENT test (testchild)>
  <!ELEMENT testchild (#PCDATA)>
]>
<test>
<testchild><![CDATA[ test once more. <<< blah <hello> <goodbye> </hello> ]]></testchild>
</test>

0
 
LVL 2

Author Comment

by:slacksoft
ID: 11843639
Dang.  

Thanks anyway.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now