Есть ли альтернатива для <assert>в XSD 1.0? - PullRequest
0 голосов
/ 08 января 2019

У меня есть XML-документ и XSD ниже. Я хочу проверить этот XML-файл по XSD, и я хочу убедиться, что сумма LineExtensionAmount и ChargeTotalAmount равна PayableAmount с использованием XML 1.0 (в .NET Framework).

Это можно сделать с помощью XSD 1.1 с использованием элемента assert, но .NET Framework не поддерживает XSD 1.1, поэтому я хочу проверить свой XML-файл с помощью XSD 1.0. Как я могу выполнить эту задачу?

<xsd:complexType name="MonetaryTotalType">
<xsd:annotation>
  <xsd:documentation>
    <ccts:Component>
      <ccts:ComponentType>ABIE</ccts:ComponentType>
      <ccts:DictionaryEntryName>Monetary Total. Details</ccts:DictionaryEntryName>
      <ccts:Definition>Information about Monetary Totals.</ccts:Definition>
      <ccts:ObjectClass>Monetary Total</ccts:ObjectClass>
    </ccts:Component>
  </xsd:documentation>
</xsd:annotation>
<xsd:sequence>
  <xsd:element ref="cbc:LineExtensionAmount" minOccurs="0" maxOccurs="1">
    <xsd:annotation>
      <xsd:documentation>
        <ccts:Component>
          <ccts:ComponentType>BBIE</ccts:ComponentType>
          <ccts:DictionaryEntryName>Monetary Total. Line Extension Amount. Amount</ccts:DictionaryEntryName>
          <ccts:Definition>The total of Line Extension Amounts net of tax and settlement discounts, but inclusive of any applicable rounding amount.</ccts:Definition>
          <ccts:Cardinality>0..1</ccts:Cardinality>
          <ccts:ObjectClass>Monetary Total</ccts:ObjectClass>
          <ccts:PropertyTerm>Line Extension Amount</ccts:PropertyTerm>
          <ccts:RepresentationTerm>Amount</ccts:RepresentationTerm>
          <ccts:DataType>Amount. Type</ccts:DataType>
        </ccts:Component>
      </xsd:documentation>
    </xsd:annotation>
  </xsd:element>
  <xsd:element ref="cbc:TaxExclusiveAmount" minOccurs="0" maxOccurs="1">
    <xsd:annotation>
      <xsd:documentation>
        <ccts:Component>
          <ccts:ComponentType>BBIE</ccts:ComponentType>
          <ccts:DictionaryEntryName>Monetary Total. Tax Exclusive Amount. Amount</ccts:DictionaryEntryName>
          <ccts:Definition>The total amount exclusive of taxes.</ccts:Definition>
          <ccts:Cardinality>0..1</ccts:Cardinality>
          <ccts:ObjectClass>Monetary Total</ccts:ObjectClass>
          <ccts:PropertyTerm>Tax Exclusive Amount</ccts:PropertyTerm>
          <ccts:RepresentationTerm>Amount</ccts:RepresentationTerm>
          <ccts:DataType>Amount. Type</ccts:DataType>
        </ccts:Component>
      </xsd:documentation>
    </xsd:annotation>
  </xsd:element>
  <xsd:element ref="cbc:TaxInclusiveAmount" minOccurs="0" maxOccurs="1">
    <xsd:annotation>
      <xsd:documentation>
        <ccts:Component>
          <ccts:ComponentType>BBIE</ccts:ComponentType>
          <ccts:DictionaryEntryName>Monetary Total. Tax Inclusive Amount. Amount</ccts:DictionaryEntryName>
          <ccts:Definition>The total amount inclusive of taxes.</ccts:Definition>
          <ccts:Cardinality>0..1</ccts:Cardinality>
          <ccts:ObjectClass>Monetary Total</ccts:ObjectClass>
          <ccts:PropertyTerm>Tax Inclusive Amount</ccts:PropertyTerm>
          <ccts:RepresentationTerm>Amount</ccts:RepresentationTerm>
          <ccts:DataType>Amount. Type</ccts:DataType>
        </ccts:Component>
      </xsd:documentation>
    </xsd:annotation>
  </xsd:element>
  <xsd:element ref="cbc:AllowanceTotalAmount" minOccurs="0" maxOccurs="1">
    <xsd:annotation>
      <xsd:documentation>
        <ccts:Component>
          <ccts:ComponentType>BBIE</ccts:ComponentType>
          <ccts:DictionaryEntryName>Monetary Total. Allowance Total Amount. Amount</ccts:DictionaryEntryName>
          <ccts:Definition>The total amount of all allowances.</ccts:Definition>
          <ccts:Cardinality>0..1</ccts:Cardinality>
          <ccts:ObjectClass>Monetary Total</ccts:ObjectClass>
          <ccts:PropertyTerm>Allowance Total Amount</ccts:PropertyTerm>
          <ccts:RepresentationTerm>Amount</ccts:RepresentationTerm>
          <ccts:DataType>Amount. Type</ccts:DataType>
        </ccts:Component>
      </xsd:documentation>
    </xsd:annotation>
  </xsd:element>
  <xsd:element ref="cbc:ChargeTotalAmount" minOccurs="0" maxOccurs="1">
    <xsd:annotation>
      <xsd:documentation>
        <ccts:Component>
          <ccts:ComponentType>BBIE</ccts:ComponentType>
          <ccts:DictionaryEntryName>Monetary Total. Charge Total Amount. Amount</ccts:DictionaryEntryName>
          <ccts:Definition>The total amount of all charges.</ccts:Definition>
          <ccts:Cardinality>0..1</ccts:Cardinality>
          <ccts:ObjectClass>Monetary Total</ccts:ObjectClass>
          <ccts:PropertyTerm>Charge Total Amount</ccts:PropertyTerm>
          <ccts:RepresentationTerm>Amount</ccts:RepresentationTerm>
          <ccts:DataType>Amount. Type</ccts:DataType>
        </ccts:Component>
      </xsd:documentation>
    </xsd:annotation>
  </xsd:element>
  <xsd:element ref="cbc:PrepaidAmount" minOccurs="0" maxOccurs="1">
    <xsd:annotation>
      <xsd:documentation>
        <ccts:Component>
          <ccts:ComponentType>BBIE</ccts:ComponentType>
          <ccts:DictionaryEntryName>Monetary Total. Prepaid Amount. Amount</ccts:DictionaryEntryName>
          <ccts:Definition>The total prepaid amount.</ccts:Definition>
          <ccts:Cardinality>0..1</ccts:Cardinality>
          <ccts:ObjectClass>Monetary Total</ccts:ObjectClass>
          <ccts:PropertyTerm>Prepaid Amount</ccts:PropertyTerm>
          <ccts:RepresentationTerm>Amount</ccts:RepresentationTerm>
          <ccts:DataType>Amount. Type</ccts:DataType>
        </ccts:Component>
      </xsd:documentation>
    </xsd:annotation>
  </xsd:element>
  <xsd:element ref="cbc:PayableRoundingAmount" minOccurs="0" maxOccurs="1">
    <xsd:annotation>
      <xsd:documentation>
        <ccts:Component>
          <ccts:ComponentType>BBIE</ccts:ComponentType>
          <ccts:DictionaryEntryName>Monetary Total. Payable_ Rounding Amount. Amount</ccts:DictionaryEntryName>
          <ccts:Definition>The rounding amount (positive or negative) added to the calculated Line Extension Total Amount to produce the rounded Line Extension Total Amount.</ccts:Definition>
          <ccts:Cardinality>0..1</ccts:Cardinality>
          <ccts:ObjectClass>Monetary Total</ccts:ObjectClass>
          <ccts:PropertyTermQualifier>Payable</ccts:PropertyTermQualifier>
          <ccts:PropertyTerm>Rounding Amount</ccts:PropertyTerm>
          <ccts:RepresentationTerm>Amount</ccts:RepresentationTerm>
          <ccts:DataType>Amount. Type</ccts:DataType>
        </ccts:Component>
      </xsd:documentation>
    </xsd:annotation>
  </xsd:element>
  <xsd:element ref="cbc:PayableAmount" minOccurs="1" maxOccurs="1">
    <xsd:annotation>
      <xsd:documentation>
        <ccts:Component>
          <ccts:ComponentType>BBIE</ccts:ComponentType>
          <ccts:DictionaryEntryName>Monetary Total. Payable_ Amount. Amount</ccts:DictionaryEntryName>
          <ccts:Definition>The total amount to be paid.</ccts:Definition>
          <ccts:Cardinality>1</ccts:Cardinality>
          <ccts:ObjectClass>Monetary Total</ccts:ObjectClass>
          <ccts:PropertyTermQualifier>Payable</ccts:PropertyTermQualifier>
          <ccts:PropertyTerm>Amount</ccts:PropertyTerm>
          <ccts:RepresentationTerm>Amount</ccts:RepresentationTerm>
          <ccts:DataType>Amount. Type</ccts:DataType>
        </ccts:Component>
      </xsd:documentation>
    </xsd:annotation>
  </xsd:element>
</xsd:sequence>
<xsd:assert test="PayableAmount = LineExtensionAmount + ChargeTotalAmount"/>

Это мой XML-файл

<cac:LegalMonetaryTotal>
  <cbc:LineExtensionAmount currencyID="NOK">1013.29</cbc:LineExtensionAmount>
  <cbc:TaxExclusiveAmount currencyID="NOK">1118.29</cbc:TaxExclusiveAmount>
  <cbc:TaxInclusiveAmount currencyID="NOK">1118.29</cbc:TaxInclusiveAmount>
  <cbc:AllowanceTotalAmount currencyID="NOK">0.00</cbc:AllowanceTotalAmount>
  <cbc:ChargeTotalAmount currencyID="NOK">105.00</cbc:ChargeTotalAmount>
  <cbc:PrepaidAmount currencyID="NOK">0.00</cbc:PrepaidAmount>
  <cbc:PayableRoundingAmount currencyID="NOK">0.00</cbc:PayableRoundingAmount>
  <cbc:PayableAmount currencyID="NOK">1118.29</cbc:PayableAmount>
</cac:LegalMonetaryTotal>
...