3

Having an XML document like this:

<Fathers>
  <Father ID="1">
    <Name>Homer</Name>
    <Sons>
       <Son ID="1">
           <Name>Bart</Name>
       </Son>
    </Sons>
  </Father>
</Fathers>

Is it valid to have the same attribute name ID in different nested tags?

Also, is it valid to have duplicate ID values?

Abdulrahman Bres
  • 2,603
  • 1
  • 20
  • 39

1 Answers1

4

ID attribute values must be unique in an XML document:

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.

Regarding your other question, yes, it is ok to have the same attribute names, even ID, among nested elements.

dbc
  • 104,963
  • 20
  • 228
  • 340
kjhughes
  • 106,133
  • 27
  • 181
  • 240