Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring an attribute for a different namespace in XML Schema

I've been using an XML format that is a mix of different existing formats and some custom elements and attributes, and I thought I should write a schema for those custom bits.

One thing I do is use custom attributes on elements in existing formats, like this:

<ns1:something attA="b" attB="a" ns2:extraAtt="c"/>

I understand that doing this is allowed but I cannot think how to declare my "extraAtt" in XML Schema or, worse, in a DTD.

I have tried reading the specification, but it could just as well be written in Chinese as far as I am concerned. Most tutorials talk only about "name", "type", and "use", e.g. this one and that one.

like image 624
scozy Avatar asked Sep 03 '13 17:09

scozy


1 Answers

Each schema document defines components (pieces of a schema) for one namespace. So to define your attribute ns2:extraAtt you want a schema document something like this one:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://example.com/my-ns2">
  <xs:attribute name="extraAtt" type="xs:anySimpleType"/>
</xs:schema>

The declaration of element ns1:something will need to allow for this attribute somehow, either with an attribute reference (<xs:attribute ref="ns2:extraAtt"/>) or with an attribute wildcard (<xs:anyAttribute namespace="http://example.com/my-ns2"/> or similar).


Sorry about the legibility of the spec; it's a long story, but essentially some members of the WG did not think people like you exist ("no one except implementors reads the spec, and as long as they don't complain it's readable enough" -- at least, that was what they said before some implementors did complain, loudly and bitterly; then they just changed the subject).

like image 79
C. M. Sperberg-McQueen Avatar answered Oct 15 '22 16:10

C. M. Sperberg-McQueen