Re: [xml] XML Schema, unique and namespaces



Hi there. A few points:

* Not sure this list is really an appropriate place to ask questions
  about the W3C XML Schema Language.

* Why are you using it, anyway? (I generally advise against using any
  constraint language other than DSDL (i.e., RELAX NG, ISO
  Schematron, et al.) unless circumstances absolutely require it.)

* To be honest, I don't know how to do this in XSD. But the following
  Schematron schema checks for uniqueness of the eye-dee= attribute.
  (I just couldn't bring myself to put a "/" into an attribute named
  "id", sorry :-)

  <?xml version="1.0" encoding="UTF-8"?>
  <schema xmlns="http://purl.oclc.org/dsdl/schematron";>
    <pattern>
      <rule context="*[ eye-dee]">
        <report test="./@eye-dee = //*[generate-id(.) != generate-id(current())]/@eye-dee">
          eye-dee= values must be unique
        </report>
      </rule>
    </pattern>
  </schema>

I'am trying to write a xml schema which must validate that a given
attribute is unique.

A (valid) simple example of the problem could look like this:
<root xmlns="http://ns2"; >
  <a id="a/1" />
  <a id="a/2" >
    <a id="a/3" />
    <a id="a/4"/>
  </a>
</root>

An invalid example (where the ID field is not unique) could look like this:
<root xmlns="http://ns2"; >
  <a id="a/1" />
  <a id="a/2" >
    <a id="a/1" />
    <a id="a/4"/>
  </a>
</root>

The schema I have been experimenting with looks like this:

<xsd:schema
  xmlns:xsd="http://www.w3.org/2001/XMLSchema";
  xmlns:ptt="http://ns2";
  targetNamespace="http://ns2";
  elementFormDefault="qualified" >

  <xsd:element name="root" type="ptt:myList">
    <xsd:unique name="myId">
      <xsd:selector xpath="ptt:*"/>
      <xsd:field xpath="@id"/>
    </xsd:unique>
  </xsd:element>

  <xsd:complexType name="myList">
    <xsd:sequence minOccurs="1">
      <xsd:element name="a" minOccurs="1" maxOccurs="unbounded"
type="ptt:asdf" />
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="asdf">
    <xsd:sequence minOccurs="1">
      <xsd:element name="a" minOccurs="0" maxOccurs="unbounded"
type="ptt:asdf" />
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:string"/>
  </xsd:complexType>
</xsd:schema>

I belive my problem is, that I can not figure out the correct xpath
to write in the selector.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]