Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

DTD validation problems

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Extract XML Data from using TSQL 5 59
XML XSL Choose example 3 30
Powershell XML in variable 4 23
tutorial for ebay api 3 55
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
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…

790 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