XSD-схема для этого фрагмента - PullRequest
0 голосов
/ 23 ноября 2010

Я пишу схему, и я не могу думать о том, как представить этот фрагмент XML:

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

То, что я изначально создал, было:

<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>

Но это неправильно, поскольку атрибуты применяются к элементу ActionTaken, а не к элементам Description.

Примечание : существует ли ЛЮБОЙ способ объявления атрибутов перед элементами? В конце концов, атрибуты приходят перед элементами!

Итак, я пытаюсь понять, как вставить атрибуты в элемент Description:

<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:sequence>
    </xs:complexType>
</xs:element>

Это не работает, потому что вы не можете иметь attribute в sequence. я попробовал:

<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>

Но это не работает из-за того, кого, черт возьми, знает.

я мог бы продолжать беспорядочно пытаться s h tuff; или я могу получить реальный ответ.


Попытка 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>

Попытка 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>

Попытка 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>

Верблюд: лошадь, спроектированная комитетом
XSD: разработано комитетом

1 Ответ

3 голосов
/ 23 ноября 2010

я мог бы продолжать беспорядочно пробовать s h tuff; или я мог бы получить реальный ответ.

Предлагаю ознакомиться с учебником W3Schools XSD .

Что вы хотите сделать, это определить атрибуты внутри элемента, который определен как сложный тип:

<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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...