简体   繁体   中英

Element with attributes with the same name from two namespaces

I am working on an XSD file including elemets such as:

<xs:element name="group">
    <xs:complexType>
      <xs:attribute name="role" type="xs:string"/>
      <xs:attribute ref="xlink:role"/>
    </xs:complexType>
</xs:element>

Where no type is defined for the 'role' Attribute in the xlink namespace. How would an XML with this Schema look like? How should I know which attribute 'role' is meant in the XML? What is the purpose of making such attributes with the same name?

This is how XML may look like:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<group xmlns:xlink="http://www.w3.org/1999/xlink" role="role1" xlink:role="http://uri1"/>

A name, as you see in the XSD, is qualified; attributes, in your case - or at least for the test XSD I've used - could also be qualified or not. By virtue of being qualified, { http://www.w3.org/1999/xlink }role is therefore different than {}role.

As to the purpose... why do we have homonyms? I am sure that through the use of synonyms one may improve the quality of a contract, particularly when dealing with people not fond of XML namespaces, or whatever... I would not comment for your particular case, since I wouldn't know if role is indeed a small price to pay, speaking about the confusion it created, vs. how well is entranced in the business vocabulary your XSD is maybe trying to capture/apply.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM