Checking XML DTD syntax and validating XML

  • Thread starter Clifford W. Racz
  • Start date
C

Clifford W. Racz

Does anyone know of a decent tool, preferably free, that will check and validate DTD syntax, to make sure that my DTD is correct?

The only tool that I have found thus far is the IBM visual DTD tool, which I do like, but is limited. Basically, your DTD is "good" when it parses... and I am not sure this is the best way to do it.



As for validation of XML, I have found a great tool, xmlvalid, here:
< http://www.elcel.com/products/xmlvalid.html >


Cliff
 
S

Sebastian Tomac

Hi Cliff

xmlspy from altova is contains a DTD validator. Xmlspy is an excellent tool.
Unfortunately it is not free, however you may download a 30day trial from
their website.

/Sebastian www.tomac.se

Clifford W. Racz said:
Does anyone know of a decent tool, preferably free, that will check and
validate DTD syntax, to make sure that my DTD is correct?
The only tool that I have found thus far is the IBM visual DTD tool, which
I do like, but is limited. Basically, your DTD is "good" when it parses...
and I am not sure this is the best way to do it.
 
C

Clifford W. Racz

Thanks Rainer, but that only validates XML files, not DTD syntax checking.


Clifford
 
R

Rainer Typke

If you refer to a DTD in a checked XML document, the XML validator
asks you to upload that as well and also validates it, if I am not
mistaken.

Cheers,

Rainer
 
C

Clifford W. Racz

Oh, I see.

The tool does validate an uploaded XML Schema against the XML Schema definition (again, another schema).

The tool does not check DTD Syntax though. It treats it like and XSD and fails on the first entity.

Thanks though for the comment.
 
R

Rainer Typke

Clifford W. Racz said:
The tool does validate an uploaded XML Schema against the XML Schema definition (again, another schema).

The tool does not check DTD Syntax though. It treats it like and XSD and fails on the first entity.
....

Well, you can't upload and check a DTD directly. But there is a way of
forcing the tool to actually perform a DTD syntax check: just write an
XML file that does nothing except for referring to your DTD and upload
it. The tool will then prompt you for the DTD, you can upload it in a
second step, and if there is a syntax error in your DTD, you will get
an error message. If the DTD is correct but your dummy XML file does
not conform to it, that fact will be reported after any errors in the
DTD.

This works for both DTDs and XSDs.

You can test this workaround by using an error-free pair of an XML and
DTD file (for example the files I will attach below), then insert a
syntax error in the DTD (for example, change an ATTLIST into an
ATLIST). The tool will then report that syntax error.

Hope this clears it up. I see that it would be a nice future feature
for the site to also offer syntax checks for DTD files without XML
files, so you are not forced to do that workaround.

Rainer

XML file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE personnel SYSTEM "personal.dtd">
<personnel>

<person id="Big.Boss">
<name><family>Boss</family> <given>Big</given></name>
<email>[email protected]</email>
<link subordinates="one.worker two.worker three.worker four.worker
five.worker"/>
</person>

<person id="one.worker">
<name><family>Worker</family> <given>One</given></name>
<email>[email protected]</email>
<link manager="Big.Boss"/>
</person>

<person id="two.worker">
<name><family>Worker</family> <given>Two</given></name>
<email>[email protected]</email>
<link manager="Big.Boss"/>
</person>

<person id="three.worker">
<name><family>Worker</family> <given>Three</given></name>
<email>[email protected]</email>
<link manager="Big.Boss"/>
</person>

<person id="four.worker">
<name><family>Worker</family> <given>Four</given></name>
<email>[email protected]</email>
<link manager="Big.Boss"/>
</person>

<person id="five.worker">
<name><family>Worker</family> <given>Five</given></name>
<email>[email protected]</email>
<link manager="Big.Boss"/>
</person>

</personnel>


DTD:

<?xml encoding="UTF-8"?>
<!ELEMENT personnel (person)+>

<!ELEMENT person (name,email*,url*,link?)>
<!ATTLIST person id ID #REQUIRED>
<!ATTLIST person note CDATA #IMPLIED>
<!ATTLIST person contr (true|false) 'false'>
<!ATTLIST person salary CDATA #IMPLIED>

<!ELEMENT name ((family,given)|(given,family))>

<!ELEMENT family (#PCDATA)>

<!ELEMENT given (#PCDATA)>

<!ELEMENT email (#PCDATA)>

<!ELEMENT url EMPTY>
<!ATTLIST url href CDATA 'http://'>

<!ELEMENT link EMPTY>
<!ATTLIST link manager IDREF #IMPLIED>
<!ATTLIST link subordinates IDREFS #IMPLIED>

<!NOTATION gif PUBLIC '-//APP/Photoshop/4.0' 'photoshop.exe'>
 
C

Clifford W. Racz

Rainer,


Ahh... I see what you are saying. This is effectively verifying syntax by failing if it doesn't parse in the XML validator. And, if it fails to parse, it throws an error and passes that along.

That is what I am doing now to check my DTDs. If this is the best I can do without spending hundreds of dollars on a program, then so be it. It always helps to have another data point...


Thanks,
Clifford
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top