Declaring an attribute for a different namespace in XML Schema

不问归期 提交于 2019-12-05 05:18:20

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).

To declare just the attribute you can use this XSD:

<xs:schema 
  targetNamespace="theNamespaceUri"
  elementFormDefault="qualified"
  attributeFormDefault="qualified"
  xmlns="theNamespaceUri"
  xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:attribute name="extraAtt" type="xs:string">
  </xs:attribute>

</xs:schema>

(assuming extraAtt is a simple string - you can use any type, or restrict an existing type etc.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!