W3C home > Mailing lists > Public > www-xml-schema-comments@w3.org > January to March 2007

Re: text() in <xs:field> xpaths

From: Sandy Gao <sandygao@ca.ibm.com>
Date: Thu, 8 Feb 2007 12:22:20 -0500
To: Erik Wilde <dret@berkeley.edu>
Cc: www-xml-schema-comments@w3.org
Message-ID: <OF5761DD74.E62DAE46-ON8525727C.005DF887-8525727C.005F6E20@ca.ibm.com>
Erik,

> currently, it is impossible to write an identity constraint which 
> ensures the uniqueness of the tag element contents within the context 
> of the <tags> element, because the field xpath may only select 
> elements or attributes, ...

How about:

 <xs:element name="tags">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="tag" type="xs:string" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
  <xs:unique name="uniqueTags">
    <xs:selector xpath="tag"/>
    <xs:field xpath="."/>
  </xs:unique>
</xs:element>

Note that when an element matches a field, it's its "value" (content) that 
matters.

And "text()" may even work against your will. For example,

 <xs:element name="tags">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="tag" type="xs:decimal" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
  <xs:unique name="uniqueTags">
    <xs:selector xpath="tag"/>
    <xs:field xpath="."/>
  </xs:unique>
</xs:element>

<tags>
  <tag>1</tag>
  <tag>1.0</tag>
  <tag>001</tag>
</tags>

In this case, because all values are typed "decimal", they are all the 
same value and should be a violation of the "unique" constraint. But if 
"text()" is used, they will be considered different.

On a related topic ... Unfortunately schema 1.0 requires all fields must 
have a simple type, which means if you want "tag" to have a complex type 
(even with simple content), it won't work. The good news is that many 
validators took the liberty of interpreting that as "simple type or 
complex type with simple content" and would still accept your example when 
"tag" has a complex type (which allows attributes), as long as its content 
is simple. Future editions of Schema 1.0 or Schema 1.1 *may* fix this 
problem.

Thanks,
Sandy Gao
XML Parser Development, IBM Canada
(1-905) 413-3255
sandygao@ca.ibm.com


www-xml-schema-comments-request@w3.org wrote on 2006-12-27 05:23:21 AM:

> 
> 
> 
> 
> hello.
> 
> i suggest to add "text()" to the allowed xpath subset for the 
> <xsl:field> element. consider the following xml fragment:
> 
> <tags>
>    <tag>XML</tag>
>    <tag>XML Schema</tag>
>    <tag>XPath</tag>
> </tags>
> 
> currently, it is impossible to write an identity constraint which 
> ensures the uniqueness of the tag element contents within the context 
> of the <tags> element, because the field xpath may only select 
> elements or attributes, but not the text() node relative to the <tag> 
> element selected by the selector.
> 
> i always found this to be a bug in the specification of identity 
> constraints, and xml schema 1.1 could be a good opportunity to fix it.
> 
> kind regards and a happy new year,
> 
> erik wilde   tel:+1-510-6432253 - fax:+1-510-6425814
>         dret@berkeley.edu  -  http://dret.net/netdret
>         UC Berkeley - School of Information (iSchool)
> 
> 
Received on Thursday, 8 February 2007 17:24:11 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Sunday, 6 December 2009 18:13:11 GMT