Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xml attributes uniqueness

Tags:

xml

Names of attributes should be unique per XML Element in xml document, isn't it?

<tag is_such_attr_is_valid="value1" is_such_attr_is_valid="value2"> </tag>

p.s. I'm interesting not how to add this constraint in validation schema (DTD, XSD). But I'm interesting in is it such case lead to well-formed xml document itself, if talking strictly.

like image 968
Konstantin Burlachenko Avatar asked Oct 20 '25 09:10

Konstantin Burlachenko


1 Answers

Yes. You can't have two XML attributes with the same expanded name in one element (see references: 1, 2). So the XML sample you posted is clearly not allowed.

Even if the two attributes were given different prefixes, as long as the prefixes are bound to the same uri, it is still not allowed. Contrasts the <bad> elements against the <good> one in the example below (adapted from the linked reference above and expanded to show good alternatives) :

<!-- http://www.w3.org is bound to foo and bar -->
<x xmlns:foo="http://www.w3.org" 
   xmlns:bar="http://www.w3.org" >
  <bad a="1"     a="2" />
  <bad foo:a="1" bar:a="2" />
  <good a="1 2"/>
  <good>
     <a>1</a>
     <a>2</a>
  </good>
  <good a="1"    b="2" />
</x>
like image 116
har07 Avatar answered Oct 24 '25 20:10

har07



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!