2009-06-01 7 views
1

サブタイプである要素をタイプを使用して選択することを検討しようとしています。したがって、サブタイプがxs:integerおよびxs:floatのテスト文書があります。スキーマ対応XQueryをセットアップする方法

スキーマで定義された型を使用するようにXQueryに指示するにはどうすればよいですか?

<?xml version="1.0" encoding="UTF-8"?> 
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="test-inherit.xsd"> 
    <int>4</int> 
    <rest-int>5</rest-int> 
    <rest-float>6</rest-float> 
</root> 

WXSスキーマ:

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

    <xs:element name="root"> 
     <xs:complexType> 
      <xs:sequence> 
       <xs:element name="int" type="xs:integer"/> 
       <xs:element name="rest-int" type="rest-int"/> 
       <xs:element name="rest-float" type="rest-float"/> 
      </xs:sequence> 
     </xs:complexType> 
    </xs:element> 

    <xs:simpleType name="rest-int"> 
     <xs:restriction base="xs:integer"> 
      <xs:maxInclusive value="10"></xs:maxInclusive> 
      <xs:minInclusive value="0"></xs:minInclusive> 
     </xs:restriction> 
    </xs:simpleType> 

    <xs:simpleType name="rest-float"> 
     <xs:restriction base="xs:float"> 
      <xs:maxInclusive value="10"></xs:maxInclusive> 
      <xs:minInclusive value="0"></xs:minInclusive> 
     </xs:restriction> 
    </xs:simpleType> 

</xs:schema> 

のXQuery:

for $integer in doc("test-inherit.xml")//element(xs:integer) 
return <integer>{$integer}</integer> 

入力ドキュメント(私が酸素とサクソン-SAを使用していることに関連があるかもしれません)

答えて

1

あなたはimporする必要がありますXQueryのスキーマ。また、ロードされたドキュメントのスキーマ(およびそれに応じてドキュメントノードに割り当てられたスキーマタイプ)を検証する場合は、式

import schema default element namespace "" at "myschema.xsd"; 
for $integer in (validate { doc("test-inherit.xml") })//schema-element(int) 
return <integer>{$integer}</integer> 
を使用する必要があります
関連する問題