2

Below is XML that has dtd schema, but it doesn't validate, why? I checked it in Eclipse and http://www.xmlvalidation.com/index.php?id=1&L=0:

<?xml version="1.0"?>
    <!DOCTYPE person-list [
    <!ELEMENT person-list (person*)>
    <!ELEMENT person (first-name,second-name?,last-name,index-no,birth-date)>
    <!ELEMENT first-name (#PCDATA)>
    <!ELEMENT second-name (#PCDATA)>
    <!ELEMENT last-name (#PCDATA)>
    <!ELEMENT index-no (#PCDATA)>
    <!ELEMENT birth-date (#PCDATA)>
    <!ATTLIST person id ID #REQUIRED>
    ]>
    <person-list>
        <person id="1">
            <first-name>ds</first-name>
            <second-name>asd</second-name>
            <last-name>asd</last-name>
            <index-no>34</index-no>
            <birth-date>1915-01-01</birth-date>
         </person>
        <person id="2">
            <first-name>dfswsf</first-name>
            <last-name>sdfsdf</last-name>
            <index-no>23</index-no>
            <birth-date>1916-02-02</birth-date>
         </person>
    </person-list> 
Karlo
  • 1,630
  • 4
  • 33
  • 57
  • 1
    Your id attribute doesn't follow the rules for id attributes – Robert Moskal Jul 07 '15 at 18:21
  • 1
    possible duplicate of [Attribute value "001" of type ID must be an NCName when namespaces are enabled](http://stackoverflow.com/questions/25256989/attribute-value-001-of-type-id-must-be-an-ncname-when-namespaces-are-enabled) – Robert Moskal Jul 07 '15 at 18:21

2 Answers2

1

By defining the id attribute of Student as an ID, it cannot start with a number since it "must match the NAME production". It can be something like "s1" and "s2", but not "1" and "2".

Validity constraint: ID

Values of type ID must match the Name production. A name must not appear more than once in an XML document as a value of this type; i.e., ID values must uniquely identify the elements which bear them.

Link:

Community
  • 1
  • 1
Jason W
  • 13,026
  • 3
  • 31
  • 62
  • If the answer helped you, please consider clicking the up arrow next to the answer. If the answer solved your question, please click the check mark under the down arrow. These things help others know your question is solved and which answers have helped, and your reputation will also increase. – Jason W Jul 09 '15 at 01:46
0

The problem is that the attribute id is of type ID which must be a valid XML name. One of the according rules says that XML names must not start with a number. So, after changing the ids to "n1" and "n2", your document will be valid, I guess.

gemue
  • 103
  • 7