Validation of an XML and DTD

Questions about XML that are not covered by the other forums should go here.
pitanga
Posts: 2
Joined: Mon Aug 21, 2017 12:21 pm

Validation of an XML and DTD

Post by pitanga »

I have a problem with my XML and DTD and I can't understand what it is. Normally, my xml is well formed:

Code: Select all

<?xml version='1.0' encoding='UTF-8' standalone="no"?>
<!DOCTYPE corpus SYSTEM "POUR.dtd">

<corpus>
<position type="contre">
<discours auteur="Aécio Neves" id="1" date="25/08/2016" lieu="Senado Federal">
blablabla
</discours>
</position>
</corpus>
My DTD:

Code: Select all

<?xml version='1.0' encoding='UTF-8'?>

<!ELEMENT corpus (position, discours)>
<!ELEMENT position (type)>
<!ATTLIST contre (#CDATA)>
<!ELEMENT discours (auteur, id, date, lieu)>
<!ATTLIST auteur (#CDATA)>
<!ATTLIST id (#CDATA)>
<!ATTLIST date (#CDATA)>
<!ATTLIST lieu (#CDATA)>
My validation: xmllint CONTRE.xml --dtdvalid CONTRE.dtd --noout

Errors:

Code: Select all

CONTRE.dtd:5: parser error : ATTLIST: no name for Attribute
<!ATTLIST contre (#CDATA)>
^
CONTRE.dtd:5: parser error : Content error in the external subset
<!ATTLIST contre (#CDATA)>
^
Can anybody help me? Thank you! :-)
Radu
Posts: 9053
Joined: Fri Jul 09, 2004 5:18 pm

Re: Validation of an XML and DTD

Post by Radu »

Hi,

You can try to google and follow a DTD tutorial.
The ATTLIST keyword connects an element with an attribute (name,value) definition.
For example if you define this element:

Code: Select all

<!ELEMENT position (type)>
you can define an attribute for it like:

Code: Select all

<!ATTLIST position contre CDATA #IMPLIED>
meaning that "contre" is an attribute of element "position", that it has simple character data and that it can be missing from the document (that #IMPLIED part).

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
pitanga
Posts: 2
Joined: Mon Aug 21, 2017 12:21 pm

Re: Validation of an XML and DTD

Post by pitanga »

Thank you! I read a tutorial and now everything works fine!!! :D
Post Reply