[oXygen-user] Checking unique Element Ids

Oxygen XML Editor Support support at oxygenxml.com
Thu Sep 20 04:56:20 CDT 2012


Hi,

You don't need XML Schema 1.1 for that. You can use xs:unique (add it to 
the end of your Item xs:element):
<xs:unique name="unique1">
    <xs:selector xpath="a|b|c|d"/>
    <xs:field xpath="@id"/>
</xs:unique>

Alternatively you could use xs:ID as the type of the "id" attribute, but 
that also means you would have to use in the XML instance IDs that begin 
with a letter or an '_'.
e.g. XML schema
<xs:attribute name="id" type="xs:ID"/>

<Item>
	<c id="a0"/>
	<a id="_1"/>

...

Regards,
Adrian

Adrian Buza
oXygen XML Editor and Author Support

Tel: +1-650-352-1250 ext.202
Fax: +40-251-461482
support at oxygenxml.com
http://www.oxygenxml.com


Olumide wrote:
> Is it possible to use XML 1.1 schema to verify that that elements in a 
> document contain unique Ids. See For example the attached test XML 
> document and Schema.
>
> Thanks.
>
> -------------- XML Document --------------
>
> <?xml version="1.0" encoding="UTF-8"?>
> <Item>
> 	<c id="0"/>
> 	<a id="1"/>
> 	<a id="2"/>
> 	<b id="3"/>
> 	<a id="4"/>
> 	<b id="0"/>
> 	<d id="6"/>
> 	<d id="7"/>
> 	<b id="3"/>
> 	<c id="1"/>
> </Item>
>
> -------------- XML 1.1 Schema --------------
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
> elementFormDefault="qualified">
>      <xs:element name="Item">
>          <xs:complexType>
>              <xs:sequence maxOccurs="unbounded">
>                  <xs:choice>
>
>                      <xs:element name="a">
>                          <xs:complexType>
>                              <xs:attribute name="id" use="required"/>
>                          </xs:complexType>
>                      </xs:element>
>
>                      <xs:element name="b">
>                          <xs:complexType>
>                              <xs:attribute name="id" use="required"/>
>                          </xs:complexType>
>                      </xs:element>
>
>                      <xs:element name="c">
>                          <xs:complexType>
>                              <xs:attribute name="id" use="required"/>
>                          </xs:complexType>
>                      </xs:element>
>
>                      <xs:element name="d">
>                          <xs:complexType>
>                              <xs:attribute name="id" use="required"/>
>                          </xs:complexType>
>                      </xs:element>
>
>                  </xs:choice>
>              </xs:sequence>
>          </xs:complexType>
>      </xs:element>
> </xs:schema>
> _______________________________________________
> oXygen-user mailing list
> oXygen-user at oxygenxml.com
> http://www.oxygenxml.com/mailman/listinfo/oxygen-user
>
>   



More information about the oXygen-user mailing list