Solved

DTD validation problems

Posted on 2008-10-15
4
376 Views
Last Modified: 2013-12-15
I'm using the DTD editor which is integrated in Eclipse 3.4.1 and I stumbled over a DTD in our system which Eclipse doesn't accept (But which seems to work in the system where it is used). I'm not very familar with DTDs and now I wonder if there are really DTD problems (which are ignored for some reason when it is used on the production system) or if the validator in Eclipse is buggy. So can you please check a few lines. Please note: I'm trying to validate the DTD, not the XML files.

Problem 1:

<!ELEMENT parent (child1?, child2?, #PCDATA)>
<!ELEMENT child1 (#PCDATA)>
<!ELEMENT child2 (#PCDATA)>

It should allow an XML document like this:

<parent>
  <child1>data<child1>
  <child2>data<child2>
  Some text data
</parent>

Validator doesn't like the #PCDATA in the first line (Error message: A '(' character or an element type is required in the declaration of element type "parent".). So first question: Is this not allowed in a DTD? Or is this a false alarm in Eclipse? Or can I write this in a different way which may be accepted by Eclipse?


Problem 2:

<!ATTLIST mail contentType  (text/plain | text/html) "text/plain" >

This should allow a "mail" element with an optional contentType attribute which can have the values "text/plain" and "text/html". But Eclipse doesn't like the slash in the values (Error message: "The enumerated type list must end with ')' in the "contentType" attribute declaration."). Again: Is this not allowed in a DTD or is it an Eclipse bug? Or can I solve this in a different way which makes Eclipse happy and still works?
0
Comment
Question by:kayahr
  • 3
4 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 22720440
I am afraid that eclipse is right

Problem 1:
To avoid ambiguity in mixed content elements, this is the only way that is allowed to define mixed content
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT parent ( #PCDATA  | child1 | child2)*>
<!ELEMENT child1 (#PCDATA)>
<!ELEMENT child2 (#PCDATA)>
Note that this is more relaxed than what you originally had, but this is the only way

It would also allow
<parent>bla bla <child2/> blabla <child1/> bla bla <child2/> blabla ...
not exactly what you want,
but there is no other way
If you really need to use DTD and limit to your example you will have to add an extra validation layer, eg. using XSLT
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 22720481
Problem 2
if you have an enumerated list of attribute values, there are limitations to the characters that are allowed (should be NMTOKEN I believe) A '/' is not an allowed character in such a list
If you really need that value, I suggest that you use XML Schema instead of DTD

I don't know which parser you have been using before, but it is obviously not a good one
0
 
LVL 7

Author Comment

by:kayahr
ID: 22720902
I digged a little bit deeper and found out that this DTD is not used at all. It's only "parsed" by humans... Oh I hate my job sometimes. I have renamed the file into a txt file and added a comment that someone may want to convert it into a XML schema and then start to really use it...

Thanks for the help. I'm happy that it's really a buggy DTD and not an Eclipse bug (Because I like to keep using Eclipse for validation).
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 22720928
welcome
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…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

757 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

22 Experts available now in Live!

Get 1:1 Help Now