I try to validate some xml data with a dtd. For that I have to use libxml2. The produced xml data looks like this:
<?xml version="1.0"?>
<root>
<vent id="1">
<usb_device_id>1</usb_device_id>
<usb_device_channel>2</usb_device_channel>
<vent_box_id>3</vent_box_id>
<vent_box_channel>4</vent_box_channel>
</vent>
</root>
My dtd looks like this:
<!ELEMENT root (vent) >
<!ELEMENT vent (usb_device_id, usb_channel, vent_box_id, vent_box_channel) >
<!ATTLIST vent id (ID) #REQUIRED >
<!ELEMENT usb_device_id (CDATA) >
<!ELEMENT usb_channel (CDATA) >
<!ELEMENT vent_box_id (CDATA) >
I use http://xmlsoft.org/html/libxml-valid.html#xmlValidateDtd on the parsed tree. With this setup I get the error message:
element vent: validity error : Value "1" for attribute id of vent is not among the enumerated set
Where I am wrong? Thanks in advance...
Your attribute id
is defined as having the type ID
. That means it has to be a valid XML name and thus its first character must not be a digit but a letter. A description can be found here or even better in the W3C documentation itself: ID and Names (copied form BLUEPIXY's comment)