How to validate a recursive XML?!?!

Having trouble installing Oxygen? Got a bug to report? Post it all here.
bene20
Posts: 1
Joined: Fri Oct 08, 2004 7:32 pm

How to validate a recursive XML?!?!

Post by bene20 »

I'm trying to validate a recursive XML against the DTD and, I'm using the xmllint to do it.

My DTD has the following structure:
<!ELEMENT index (main_title,class,ind_item+) >
<!ELEMENT main_title (#PCDATA) >
<!ELEMENT class (number,sub_title) >
<!ELEMENT number (#PCDATA) >
<!ELEMENT sub_title (#PCDATA) >
<!ELEMENT ind_item (block,text,ind_item*) >
<!ELEMENT block (#PCDATA) >
<!ELEMENT text (#PCDATA) >

And an exemplo of my XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<index>
<main_title>Construcao de Paginas WEB</main_title>
<class>
<number >1</number>
<sub_title>Javascript</sub_title>
</class>
<ind_item>
<block>1</block>
<text>O que e Javascript</text>
</ind_item>
<ind_item>
<block>40</block>
<text>Introducao - Subtopics</text>
<ind_item>
<block>440</block>
<text>Introducao ... 1 apresent</text>
</ind_item>
<ind_item>
<block>444</block>
<text>Introducao ... 2 mais</text>
<ind_item>
<block>4401</block>
<text>Sub Int 2.1 A</text>
<ind_item>
<block>44010</block>
<text>Sub Int 2 A</text>
</ind_item>
<ind_item>
<block>44020</block>
<text>Sub Int 2.2 A</text>
</ind_item>
</ind_item>
<ind_item>
<block>4402</block>
<text>Sub Int 2 B</text>
</ind_item>
</ind_item>
<ind_item>
<block>455</block>
<text>Introducao ... 3 sianda!!!</text>
</ind_item>
</ind_item>
<ind_item>
<block>100</block>
<text>Desenvolvimento com Javascript</text>
</ind_item>
</index>

My problem is the following: I want to prohibit the XML writer to change the order of "block" and "text", ie, The user can't write a XML as bellow:
<ind_item>
<text>Desenvolvimento com Javascript</text>
<block>100</block>
</ind_item>
(note that the tag "text" occured before the tag "block" -> It's wrong as you can see at DTD at the top os this message)

As you can see, I declared the tag block before the tag text in DTD, but when I use de xmllint to validate my wrong XML, it doesn't find the error and takes the wrong XML as valid innapropriatly.
An other problem I have is that if the user write an XML without one of these tags, the XML validator doesn't find the error too. See an example of the second kind of a wrong XML bellow:
<ind_item>
<text>Desenvolvimento com Javascript</text>
</ind_item>

I think my problem occurs because of the recursiivity... Some one told me to exclude this recursivity, but I really can't do this... :-(

Can any one help me?

Sorry for my bad english... I'm brazilian and I can hardly speak english... :-)
dsewell
Posts: 125
Joined: Mon Jun 09, 2003 6:02 pm
Location: Charlottesville, Virginia USA

xmllint works okay for me

Post by dsewell »

I tested the example you provided, and xmllint gave an error message for the invalid files.

What form of the command did you use? Note that

Code: Select all

xmllint --noout file.xml
only checks for well-formed XML. It does not use the DTD. You must use:

Code: Select all

xmllint --noout --valid file.xml
to test the validity.

(You can always use oXygen to validate your XML! It performs correctly on your sample data also.)
Post Reply