Subject:Validation error Author:Michael Salman Date:23 Nov 2015 06:29 PM
I wonder if someone could tell me why I am getting this validation error
Here is the xml file:
<?xml version="1.0"?><!DOCTYPE employees SYSTEM "file:///e:/XmlProjects/TestUml.dtd">
<employees>
<employee id="1">
<firstName>Mike</firstName>
<lastName>Smith</lastName>
</employee>
</employees>
Here is the DTD file:
<?xml version="1.0" encoding="UTF-16LE"?>
<!ELEMENT firstName (#PCDATA)>
<!ELEMENT lastName (#PCDATA)>
<!ELEMENT employee (firstName,lastName)>
<!ATTLIST employee id ID #REQUIRED>
<!ELEMENT employees (employee)>
Here is the error stylus studio gives me:
Validating TestUml.xml...
file:///e:/XmlProjects/TestUml.xml:3,18: value '1' for attribute 'id' is invalid Name or NMTOKEN value
The XML document TestUml.xml is NOT valid (1 errors)
Now if I change ID to CDATA the xml file validates. Could someone tell me what is wrong with my DTD file as far as I can tell the syntax is valid
Subject:Validation error Author:Michael Salman Date:24 Nov 2015 12:53 AM
Well I am not an xml expert but I have to disagree with you on this. First of all ID is a legal Content Type. I wrote a c# program which has an XmLDocument class which is used for parsing and manipulating xml files. It has a function called GetElementById(string) which returns an element containing the attribute. In this case I would use it like this
GetElementById("1") but this function will not work if it is not defined with the Content Type ID (which is used to identify an attribute as being unique. Stylus Studio should not report that there is a validation error as there is none
Regards Mike
Subject:Validation error Author:Michael Salman Date:24 Nov 2015 02:44 AM
I apologize it is my error. I changed it to id="one" and it now works fine. The only excuse I have is I am reading a book on xml and it gives sample xml and dtd files which are obviously erroneous
Thanks for your prompt response
Regards Mike