XSD

2014-07-24 5 views
0

안녕 내가처럼 보이는 XML, 나는이에 대한 XSD를 작성해야XSD

<ABC> 
<DEF Value="123"> 
<XYZ> 
<RootEle Text="Now" Date="SomeDate"/> 
</XYZ> 
</DEF> 
<DEF AnotherValue="123"> 
<XYZ> 
<AnotherRootEle AnotherText="NowOrNever" AnotherDate="SomeOtherDate"/> 
</XYZ> 
</DEF> 
</ABC> 

있습니다. 그러나 내가 쓴 xsd는 위의 xml에 좋지 않습니다.

<?xml version="1.0" encoding="UTF-8"?> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> 
    <xsd:element name="ABC"> 
     <xsd:complexType> 
     <xsd:sequence minOccurs="1" maxOccurs="1"> 
      <xsd:element name="DEF"> 
       <xsd:complexType> 
        <xsd:sequence minOccurs="1" maxOccurs="unbounded"> 
        <xsd:element name="XYZ"> 
         <xsd:complexType> 
          <xsd:sequence minOccurs="1" maxOccurs="1"> 
           <xsd:element name="RootEle"> 
           <xsd:complexType> 
            <xsd:attribute name="Text" use="optional"> 
             <xsd:annotation> 
              <xsd:documentation>Text</xsd:documentation> 
             </xsd:annotation> 
             <xsd:simpleType> 
              <xsd:restriction base="xsd:string"> 
              <xsd:maxLength value="40" /> 
              </xsd:restriction> 
             </xsd:simpleType> 
            </xsd:attribute> 
            <xsd:attribute name="Date" use="optional"> 
             <xsd:annotation> 
              <xsd:documentation>Date</xsd:documentation> 
             </xsd:annotation> 
             <xsd:simpleType> 
              <xsd:restriction base="xsd:string"> 
              <xsd:maxLength value="40" /> 
              </xsd:restriction> 
             </xsd:simpleType> 
            </xsd:attribute> 
           </xsd:complexType> 
           </xsd:element> 
          </xsd:sequence> 
         </xsd:complexType> 
        </xsd:element> 
        </xsd:sequence> 
        <xsd:attribute name="Value" use="optional"> 
        <xsd:annotation> 
         <xsd:documentation>Name of the flow</xsd:documentation> 
        </xsd:annotation> 
        <xsd:simpleType> 
         <xsd:restriction base="xsd:string"> 
          <xsd:maxLength value="40" /> 
         </xsd:restriction> 
        </xsd:simpleType> 
        </xsd:attribute> 
        <xsd:attribute name="AnotherValue" use="optional"> 
        <xsd:annotation> 
         <xsd:documentation>Name of interface</xsd:documentation> 
        </xsd:annotation> 
        <xsd:simpleType> 
         <xsd:restriction base="xsd:string"> 
          <xsd:maxLength value="40" /> 
         </xsd:restriction> 
        </xsd:simpleType> 
        </xsd:attribute> 
       </xsd:complexType> 
      </xsd:element> 
     </xsd:sequence> 
     </xsd:complexType> 
    </xsd:element> 
</xsd:schema> 

위의 XSD는 아래의 XML뿐만 아니라 하나가 다른 하위 요소와 반복 요소 작동하지 않는 첫번째 즉 게시를위한 좋은 보유하고 있습니다.

<ABC> 
    <DEF Value="123"> 
     <XYZ> 
      <RootEle Text="Now" Date="SomeDate"/> 
     </XYZ> 
    </DEF> 
</ABC> 

??

+0

'DEF' 요소에는 몇 가지 수정 사항이 있어야합니다. 지금 가지고있는 것은'DEF'는 많은'XYZ' 자식을 가질 수 있다는 것입니다. – sergioFC

답변

1

sergioFC 당신은 또한 당신의 XML에 AnotherRootEle이 그러나 당신은

 <xsd:element minOccurs="1" maxOccurs="unbounded" name="DEF"> 
      <xsd:complexType> 
       <xsd:sequence> 

을 가져야한다

 <xsd:element name="DEF"> 
      <xsd:complexType> 
       <xsd:sequence minOccurs="1" maxOccurs="unbounded"> 

보다

오히려 잘못된 수준으로 발생을 정의한 그의 코멘트에 정확 그것은 XSD에 전혀 나타나지 않습니다.

이 경우 다음과 같이 XYZ를 다시 정의해야합니다.

  <xsd:element name="XYZ"> 
      <xsd:complexType> 
       <xsd:sequence minOccurs="1" maxOccurs="1"> 
       <xsd:choice minOccurs="0"> 
        <xsd:element name="RootEle"> 
        <xsd:complexType> 
         <xsd:attribute name="Text" use="optional"> 
         <xsd:annotation> 
          <xsd:documentation>Text</xsd:documentation> 
         </xsd:annotation> 
         <xsd:simpleType> 
          <xsd:restriction base="xsd:string"> 
          <xsd:maxLength value="40" /> 
          </xsd:restriction> 
         </xsd:simpleType> 
         </xsd:attribute> 
         <xsd:attribute name="Date" use="optional"> 
         <xsd:annotation> 
          <xsd:documentation>Date</xsd:documentation> 
         </xsd:annotation> 
         <xsd:simpleType> 
          <xsd:restriction base="xsd:string"> 
          <xsd:maxLength value="40" /> 
          </xsd:restriction> 
         </xsd:simpleType> 
         </xsd:attribute> 
        </xsd:complexType> 
        </xsd:element> 
        <xsd:element name="AnotherRootEle"> 
        <xsd:complexType> 
         <xsd:attribute name="AnotherText" use="optional"> 
         <xsd:annotation> 
          <xsd:documentation>Text</xsd:documentation> 
         </xsd:annotation> 
         <xsd:simpleType> 
          <xsd:restriction base="xsd:string"> 
          <xsd:maxLength value="40" /> 
          </xsd:restriction> 
         </xsd:simpleType> 
         </xsd:attribute> 
         <xsd:attribute name="AnotherDate" use="optional"> 
         <xsd:annotation> 
          <xsd:documentation>Date</xsd:documentation> 
         </xsd:annotation> 
         <xsd:simpleType> 
          <xsd:restriction base="xsd:string"> 
          <xsd:maxLength value="40" /> 
          </xsd:restriction> 
         </xsd:simpleType> 
         </xsd:attribute> 
        </xsd:complexType> 
        </xsd:element> 
       </xsd:choice> 
       </xsd:sequence> 
      </xsd:complexType> 
      </xsd:element>