Question

I'm trying to validate this XML document:

<?xml version="1.0"?>
<CONTACTS>
    <CONTACT CONTACT_NUM = "1">
    <NAME>Alice</NAME>
    </CONTACT>

    <CONTACT CONTACT_NUM = "2">
    <NAME>Bob</NAME>
    </CONTACT>
</CONTACTS>

against the following DTD:

<!ELEMENT CONTACTS ANY>
<!ELEMENT CONTACT (NAME)>
<!ELEMENT NAME (#PCDATA)>
<!ATTLIST CONTACT CONTACT_NUM ID #REQUIRED>

running xmllint --dtdvalid test.dtd test.xml produces:

test.xml:3: element CONTACT: validity error : Syntax of value for attribute CONTACT_NUM of CONTACT is not valid
test.xml:7: element CONTACT: validity error : Syntax of value for attribute CONTACT_NUM of CONTACT is not valid
Document test.xml does not validate against test.dtd

Anybody spot what's wrong with the syntax of attribute CONTACT_NUM?

Was it helpful?

Solution

The value of an attribute of type ID cannot start with a digit. It must match the Name production in the XML specification, which rules out initial digits.

<CONTACT CONTACT_NUM = "_1"> or <CONTACT CONTACT_NUM = "ID1"> would be OK, for example.

References:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top