Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is XML element invalid?

Tags:

xml

<?xml version="1.0" ?>
<accounts>
    <1167/>
    <1328/>
    <1505/>
    <1536 default="true" />
    <1966/>
</accounts>

When I pass in the above XML at http://www.w3schools.com/XML/xml_validator.asp I get an error stating the line with <1167/> is invalid. I looked at the w3 description for elements, and didn't see any reason why it should be wrong. I'm sure its a simple mistake so would appreciate any help.

Thanks

like image 378
Superpolock Avatar asked Dec 02 '22 01:12

Superpolock


1 Answers

The name of an element must not start with a digit¹.

Also, the name of an element should describe the "class" or "type" of the represented entity, and be static. Might I suggest:

<accounts>
    <account number="1167"/>
    <account number="1328"/>
    <account number="1505"/>
    <account number="1536" default="true" />
    <account number="1966"/>
</accounts>

¹ For some reason, many answers here link to w3schools (which is not affiliated with the W3C). Instead, you should only trust the XML standard.

like image 95
phihag Avatar answered Dec 15 '22 22:12

phihag