开发者

XSD schema for this fragment

开发者 https://www.devze.com 2023-01-26 15:48 出处:网络
i\'m writing a schema, and i can\'t think of how to represent this xml fragment: <ActionTaken> <Description partID=\"H1\" sequenceNumber=\"01\">i did this</Description>

i'm writing a schema, and i can't think of how to represent this xml fragment:

<ActionTaken>
   <Description partID="H1" sequenceNumber="01">i did this</Description>
   <Description partID="H1" sequenceNumber="02">and then some more stuff.</Description>
</ActionTaken>

What i had initially created was:

<xs:element name="ActionTaken">
   <xs:complexType>
      <xs:sequence>
         <xs:element name="Description" type="String400" minOccurs="1" maxOccurs="99" />
      </xs:sequence>
      <xs:attribute name="partID" type="STReportTypeEnum" />
      <xs:attribute name="partSequenceNumber" type="NumericTwoRJZ" />
   </xs:complexType>
 </xs:element>

But that's wrong because the attributes are applied to the ActionTaken element, rather than the Description elements.

Note: Is there ANY way to declare attributes before the elements? Attributes do, after all, come before elements!

So i'm trying to figure out how to push the attributes down onto the Description element:

<xs:element name="ActionTa开发者_C百科ken">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Description" type="String400" minOccurs="1" maxOccurs="99" />
            <xs:attribute name="partID" type="STReportTypeEnum" />
            <xs:attribute name="partSequenceNumber" type="NumericTwoRJZ" />
        </xs:sequence>
    </xs:complexType>
</xs:element>

That doesn't work because you cannot have an attribute in the sequence. i tried:

<xs:element name="ActionTaken">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Description" type="String400" minOccurs="1" maxOccurs="99" >
                <xs:attribute name="partID" type="STReportTypeEnum" />
                <xs:attribute name="partSequenceNumber" type="NumericTwoRJZ" />
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

But that doesn't work because of who the hell knows.

i could keep randomly trying shtuff; or i could get the real answer.


Attempt 4

<xs:element name="ActionTaken">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Description" type="String400" minOccurs="1" maxOccurs="99" >
                <xs:attribute name="partID" type="STReportTypeEnum" />
                <xs:attribute name="partSequenceNumber" type="NumericTwoRJZ" />
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

Attempt 5

<xs:element name="DescriptionOfSuspiciousActivity">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Description" type="String400" minOccurs="1" maxOccurs="99">
                <xs:complexType>
                    <!--Description of Suspicious Activity (Part G) attributes-->
                    <xs:attribute name="partID" type="STReportTypeEnum" />
                    <xs:attribute name="partSequenceNumber" type="NumericTwoRJZ" />
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

Attempt 6

<xs:element name="ActionTaken">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Description" type="String400" minOccurs="1" maxOccurs="99" >
                <xs:complexType>
                    <xs:attribute name="partID" type="STReportTypeEnum" />
                    <xs:attribute name="partSequenceNumber" type="NumericTwoRJZ" />
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

Camel: a horse designed by committee

XSD: designed by committee


i could keep randomly trying shtuff; or i could get the real answer.

I suggest checking out the W3Schools XSD tutorial.

What you want to do is define the attributes inside the element which is defined as a complex type:

<xs:element name="ActionTaken"> 
  <xs:complexType> 
    <xs:sequence> 
      <xs:element name="Description" 
        type="DescriptionString400" minOccurs="1" maxOccurs="99"
      />
    </xs:sequence> 
  </xs:complexType> 
</xs:element> 
<xs:complexType name="DescriptionString400">
  <xs:simpleContent>
    <xs:extension base="String400">
      <xs:attribute name="partID" type="STReportTypeEnum" /> 
      <xs:attribute name="partSequenceNumber" type="NumericTwoRJZ" />
    </xs:extension>
  </xs:simpleContent>
</xs:complexType>
0

精彩评论

暂无评论...
验证码 换一张
取 消