2016-08-22 7 views
0

を使用してユニークとしてXML要素を定義します。私は、以下の関連するXSDを持つXMLファイルを持っているXSD

のcomplexTypeの要素「名前」「UpgraderConfigは、」ユニークである必要があります。 "UpgraderConfigContainer"定義に "unique"タグを追加しましたが、目的の動作を得ることができませんでした。

誰でも私が間違っていることについて助言してもらえますか?

<?xml version="1.0"?> 
<xs:schema targetNamespace="http://www.hp.com/maas/1.0.0/UpgraderConfig" 
      xmlns:xs="http://www.w3.org/2001/XMLSchema" 
      xmlns:config="http://www.hp.com/maas/1.0.0/UpgraderConfig" 
      elementFormDefault="qualified" 
      version="1.0.0"> 

    <xs:simpleType name="stringWithoutWhiteSpace"> 
     <xs:annotation> 
      <xs:documentation>One or more occurrences of any character which is not whitespace (i.e. not space, tab, newline, return)</xs:documentation> 
     </xs:annotation> 
     <xs:restriction base="xs:string"> 
      <xs:minLength value="1" /> 
      <xs:pattern value="\S+" /> 
     </xs:restriction> 
    </xs:simpleType> 


    <xs:complexType name="UpgraderConfigContainer"> 
     <xs:sequence minOccurs="0" maxOccurs="unbounded"> 
      <xs:element name="Upgrader" type="config:UpgraderConfig" > 
       <xs:unique name="uniqueUgraderName"> 
        <xs:selector xpath="Upgrader"/> 
        <xs:field xpath="name"/> 
       </xs:unique> 
      </xs:element> 
     </xs:sequence> 
    </xs:complexType> 

    <xs:complexType name="UpgraderConfig"> 
     <xs:sequence> 
      <xs:element name="name" type="xs:string"/> 
      <xs:element name="className" type="config:stringWithoutWhiteSpace"/> 
     </xs:sequence> 
    </xs:complexType> 

    <xs:element name="UpgraderConfigs" type="config:UpgraderConfigContainer" /> 

</xs:schema> 

答えて

1

固有の制約が低すぎます。独自の要素は一意ではありません。独自の制約を持つコンテナのみを含むコンテナのみが使用できます。 UpgraderConfigContainerは、コンテナではないため、少し先行しています。代わりに、それはバインドされていない要素です。つまり、ゼロ以上のを持っています。 を含む要素には、固有の制約がなければなりません。 UpgraderConfigsに追加する必要があります。

<?xml version="1.0"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:config="http://www.hp.com/maas/1.0.0/UpgraderConfig" targetNamespace="http://www.hp.com/maas/1.0.0/UpgraderConfig" elementFormDefault="qualified" version="1.0.0"> 
    <xs:simpleType name="stringWithoutWhiteSpace"> 
     <xs:annotation> 
      <xs:documentation>One or more occurrences of any character which is not whitespace (i.e. not space, tab, newline, return)</xs:documentation> 
     </xs:annotation> 
     <xs:restriction base="xs:string"> 
      <xs:minLength value="1"/> 
      <xs:pattern value="\S+"/> 
     </xs:restriction> 
    </xs:simpleType> 
    <xs:complexType name="UpgraderConfigContainer"> 
     <xs:sequence minOccurs="0" maxOccurs="unbounded"> 
      <xs:element name="Upgrader" type="config:UpgraderConfig"/> 
     </xs:sequence> 
    </xs:complexType> 
    <xs:complexType name="UpgraderConfig"> 
     <xs:sequence> 
      <xs:element name="name" type="xs:string"/> 
      <xs:element name="className" type="config:stringWithoutWhiteSpace"/> 
     </xs:sequence> 
    </xs:complexType> 
    <xs:element name="UpgraderConfigs" type="config:UpgraderConfigContainer"> 
     <xs:unique name="uniqueUpgraderName"> 
      <xs:selector xpath="config:Upgrader"/> 
      <xs:field xpath="config:name"/> 
     </xs:unique> 
    </xs:element> 
</xs:schema> 
+0

私は含まれている要素がそれにユニークな制約を持つことしかできないことを知りませんでした。ありがとう、それは実際に動作します。 –

関連する問題