Solved

DTD validation problems

Posted on 2008-10-15
4
379 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem to Popup 2 82
Word files to Wordpress Posts 2 53
JQuery to parse xml string and get element by id 4 35
Eliminate additional border 1 18
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

773 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