XSD 1.0中是否有<assert>的替代元素?

时间:2019-01-08 04:34:59

标签: .net xsd-1.0

我下面有XML文档和XSD。我想针对XSD验证此XML文件,并希望使用XML 1.0(在.NET框架中)确保LineExtensionAmount和ChargeTotalAmount的总和等于PayableAmount。

这可以通过使用assert元素的XSD 1.1来完成,但是.NET框架不支持XSD 1.1,因此我想使用XSD 1.0验证我的XML文件。如何实现此任务?

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

0 个答案:

没有答案