2

Is

<root>
    <x x="y" />
</root>

valid XML?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
Julian Habekost
  • 262
  • 1
  • 4
  • 17

1 Answers1

3

Yes, it's fine to have elements and attributes with the same name, but note the following:

  • It's not commonly done because it can be confusing and rarely models real world entities accurately.
  • Terminology:
    • Well-formed XML may have elements and attributes with the same names because there's nothing in the W3C Recommendation prohibiting it.
    • Valid XML may have elements and attributes with the same name if permitted by an associated schema (DTD, XSD, etc) because validity is function of the relationship between an XML document and a schema, not an intrinsic property of an XML document.
Community
  • 1
  • 1
kjhughes
  • 106,133
  • 27
  • 181
  • 240