2011-10-20 10 views
5

xs:unique指定子をXMLファイルで使用することができません。私はちょうど動作するXPathを試すことができないようです。私はこの質問のコード量について謝罪しますが、以下で間違っていることを指摘できる人には非常に感謝しています。私が何をしても、要素の@ref属性を取得して、値を複製する際にエラーを報告することはできません(各refは一意でなければなりません)。XMLスキーマで一意の値を指定する方法

情報への助けや指導は、非常に感謝して受け取ります。種類が希望

、パトリック

は、これが私のスキーマです:

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema id="Artworks" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:aw="http://www.fourthwish.co.uk/data/Artworks.xsd" 
xmlns="http://www.fourthwish.co.uk/data/Artworks.xsd" 
targetNamespace="http://www.fourthwish.co.uk/data/Artworks.xsd" 
elementFormDefault="qualified" 
> 
<xs:element name="artworks"> 
    <xs:complexType> 
    <xs:sequence minOccurs="0" maxOccurs="unbounded"> 
      <xs:element name="artwork" type="ArtworkType"> 
       <xs:unique name="uniqueRef"> 
        <xs:selector xpath="artwork"/> 
        <xs:field xpath="@ref"/> 
       </xs:unique> 
      </xs:element> 
     </xs:sequence> 
    </xs:complexType> 
</xs:element> 
<xs:complexType name="ArtworkType"> 
    <xs:sequence> 
     <xs:element name="title" type="xs:string"/> 
    </xs:sequence> 
    <xs:attribute name="ref" type="xs:nonNegativeInteger"/> 
</xs:complexType> 
</xs:schema> 

そして、これは私のXMLファイルです:

<?xml version="1.0" encoding="utf-8" standalone="yes"?> 
<artworks 
xmlns="http://www.fourthwish.co.uk/data/Artworks.xsd" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.fourthwish.co.uk/data/Artworks.xsd Artworks.xsd" 
> 
<artwork ref="1"> 
    <title>Title String</title> 
</artwork> 
<artwork ref="1"> 
    <title>Title String</title> 
</artwork> 
</artworks> 

は、なぜ私は、重複REFのエラーを得ることはありません値? Arrrggghhh!私はインターネット上のすべてを読んだ。助けてください。

答えて

3

使用この:

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema id="Artworks" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:aw="http://www.fourthwish.co.uk/data/Artworks.xsd" 
xmlns="http://www.fourthwish.co.uk/data/Artworks.xsd" 
targetNamespace="http://www.fourthwish.co.uk/data/Artworks.xsd" 
elementFormDefault="qualified" 
> 
    <xs:element name="artworks"> 
    <xs:complexType> 
     <xs:sequence minOccurs="0" maxOccurs="unbounded"> 
     <xs:element name="artwork" type="ArtworkType"/> 
     </xs:sequence> 
    </xs:complexType> 

    <xs:unique name="uniqueRef"> 
     <xs:selector xpath="aw:artwork"/> 
     <xs:field xpath="@ref"/> 
    </xs:unique> 

    </xs:element> 

    <xs:complexType name="ArtworkType"> 
    <xs:sequence> 
     <xs:element name="title" type="xs:string"/> 
    </xs:sequence> 
    <xs:attribute name="ref" type="xs:nonNegativeInteger"/> 
    </xs:complexType> 
</xs:schema> 
1

あなたはサクソン-EEを通じて、このスキーマを実行した場合、それはあなたを伝える:

警告:test.xsdの13行目: 複合体をタイプArtworkTypeは{}のアートワークという名前の子要素を許可しません

これは基本的にあなたがアートワークがしたがって、接頭辞が必要です。

関連する問題