2017-01-30 31 views
0

我想验证this schema的XML文件。针对XSD的验证忽略XML文件中的重复密钥

有一个主表部分,它包含数据,然后从文件的其他地方引用数据。 MasterFile表应该包含唯一的条目,以便它们可以从xml文件中的其他地方引用。

但是我无法弄清楚什么应该是无效的键。我曾尝试使用XML工具和Eclipse在XML记事本,Notepad ++中进行验证。从上述舍姆税率表的

定义:

<xs:element name="TaxTable" minOccurs="0"> 
<xs:complexType> 
    <xs:sequence> 
     <xs:element name="TaxTableEntry" maxOccurs="unbounded"> 
      <xs:complexType> 
       <xs:sequence> 
        <xs:element name="TaxType" type="FAIAcodeType"> 
        </xs:element> 
        <xs:element name="Description" type="FAIAlongtextType"> 
        </xs:element> 
        <xs:element name="TaxCodeDetails" maxOccurs="unbounded"> 
         <xs:complexType> 
           <xs:sequence> 
            <xs:element name="TaxCode" type="FAIAcodeType"> 
            </xs:element> 
            <xs:element name="EffectiveDate" type="xs:date" minOccurs="0"> 
            </xs:element> 
            <xs:element name="ExpirationDate" type="xs:date" minOccurs="0"> 
            </xs:element> 
            <xs:element name="Description" type="FAIAlongtextType" minOccurs="0"> 
            </xs:element> 
            <xs:choice minOccurs="0"> 
             <xs:element name="TaxPercentage" type="xs:decimal"> 
             </xs:element> 
             <xs:element name="FlatTaxRate" type="AmountStructure"> 
             </xs:element> 
            </xs:choice> 
            <xs:element name="Country" type="ISOCountryCode"> 
            </xs:element> 
            <xs:element name="Region" type="FAIAcodeType" minOccurs="0"> 
            </xs:element> 
           </xs:sequence> 
         </xs:complexType> 
        </xs:element> 
       </xs:sequence> 
      </xs:complexType> 
     </xs:element> 
    </xs:sequence> 
</xs:complexType> 
</xs:element> 

密钥和KeyRef定义:最小XML的文件的

<xs:key name="KeyTaxType"> 
<xs:selector xpath="MasterFiles/TaxTable/TaxTableEntry"/> 
<xs:field xpath="TaxType"/> 
</xs:key> 

<xs:keyref name="RefRegistrationTaxType" refer="KeyTaxType"> 
<xs:selector xpath="Header/Company/TaxRegistration"/> 
<xs:field xpath="TaxType"/> 
</xs:keyref> 

<xs:keyref name="RefCustomerTaxType" refer="KeyTaxType"> 
<xs:selector xpath="MasterFiles/Customers/Customer/TaxRegistration"/> 
<xs:field xpath="TaxType"/> 
</xs:keyref> 

实施例那应该打破TaxType键约束,但是这验证在3不同的工具。验证适用于除键之外的所有内容,因为当我添加不存在的元素或更改顺序中的元素顺序时会出错,所以我可以看到验证至少发生。

<?xml version="1.0" encoding="UTF-8"?> 
<xs:AuditFile 
xmlns:xs="urn:OECD:StandardAuditFile-Taxation/2.00" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="urn:OECD:StandardAuditFile-Taxation/2.00 ../../main/resources/FAIA_v_2_01_full.xsd "> 
<xs:Header> 
    <xs:AuditFileVersion>2.0.1</xs:AuditFileVersion> 
    <xs:AuditFileCountry>LU</xs:AuditFileCountry> 
    <xs:AuditFileDateCreated>2001-01-01</xs:AuditFileDateCreated> 
    <xs:SoftwareCompanyName>TestCorp</xs:SoftwareCompanyName> 
    <xs:SoftwareID>Test</xs:SoftwareID> 
    <xs:SoftwareVersion>Test</xs:SoftwareVersion> 
    <xs:Company> 
     <xs:RegistrationNumber>123456</xs:RegistrationNumber> 
     <xs:Name>Test Corporation</xs:Name> 
     <xs:Address> 
      <xs:City>London</xs:City> 
      <xs:PostalCode>123456</xs:PostalCode> 
     </xs:Address> 
     <xs:Contact> 
      <xs:ContactPerson> 
       <xs:FirstName>John</xs:FirstName> 
       <xs:LastName>Doe</xs:LastName> 
      </xs:ContactPerson> 
      <xs:Telephone>45646825</xs:Telephone> 
     </xs:Contact> 
     <xs:TaxRegistration> 
      <xs:TaxRegistrationNumber>LU1234566-78</xs:TaxRegistrationNumber> 
      <xs:TaxType>TVA</xs:TaxType> 
      <xs:TaxNumber>LU1234566-78</xs:TaxNumber> 
     </xs:TaxRegistration> 
    </xs:Company> 
    <xs:DefaultCurrencyCode>EUR</xs:DefaultCurrencyCode> 
    <xs:SelectionCriteria> 
     <xs:TaxReportingJurisdiction>xs:TaxReportingJurisdiction</xs:TaxReportingJurisdiction> 
     <xs:CompanyEntity>xs:CompanyEntity</xs:CompanyEntity> 
     <xs:SelectionStartDate>2015-01-01</xs:SelectionStartDate> 
     <xs:SelectionEndDate>2015-12-31</xs:SelectionEndDate> 
     <xs:DocumentType>xs:DocumentType</xs:DocumentType> 
     <xs:OtherCriteria>First Other Criteria</xs:OtherCriteria> 
     <xs:OtherCriteria>Second Other Criteria</xs:OtherCriteria> 
    </xs:SelectionCriteria> 
    <xs:HeaderComment>xs:HeaderComment</xs:HeaderComment> 
    <xs:TaxAccountingBasis>Invoice Accounting</xs:TaxAccountingBasis> 
    <xs:TaxEntity>xs:TaxEntity</xs:TaxEntity> 
</xs:Header> 
<xs:MasterFiles> 
<xs:TaxTable> 
    <xs:TaxTableEntry> 
     <xs:TaxType>TVA</xs:TaxType> 
     <xs:Description>Taxe sur la valeur ajoutée</xs:Description> 
     <xs:TaxCodeDetails> 
      <xs:TaxCode>1</xs:TaxCode> 
      <xs:EffectiveDate>2010-01-01</xs:EffectiveDate> 
      <xs:Description>LU/01/0/0.00 - TVA sur ventes</xs:Description> 
      <xs:TaxPercentage>0.0</xs:TaxPercentage> 
      <xs:Country>LU</xs:Country> 
     </xs:TaxCodeDetails> 
    </xs:TaxTableEntry> 
    <xs:TaxTableEntry> 
     <xs:TaxType>TVA</xs:TaxType> 
     <xs:Description>Taxe sur la valeur ajoutée</xs:Description> 
     <xs:TaxCodeDetails> 
      <xs:TaxCode>1</xs:TaxCode> 
      <xs:EffectiveDate>2010-01-01</xs:EffectiveDate> 
      <xs:Description>LU/01/0/0.00 - TVA sur ventes</xs:Description> 
      <xs:TaxPercentage>0.0</xs:TaxPercentage> 
      <xs:Country>LU</xs:Country> 
     </xs:TaxCodeDetails> 
    </xs:TaxTableEntry> 
</xs:TaxTable> 
</xs:MasterFiles> 

更新,以表明它似乎是一个验证问题。

回答

0

我的理解与你所描述的不同。

总之,selector选择什么元素必须是唯一的,而field选择什么使他们独特

在这种情况下,选择器选择整个列表TaxTableEntry s,并且对于其中的每一个,该字段选择其TaxType。具体而言,这意味着在此列表中(即不在列表中的每个项目内,但在整个列表中),TaxType必须完全不同。

随着keyRef情况下,它们的值可以被引用为外键明确一个MasterFile(或你放置key定义)内确定一个TaxTableEntry

如果您身边的验证行为背离了这一点,请随意分享一个XML实例,该实例的行为与您期望的不同,并且我们可以提供更多帮助。

+0

我还假设它是如何工作的,或者至少该架构的创建者希望它如何工作。我编辑了我的帖子并添加了一个用重复的TaxType验证的例子。 – johankr

+0

谢谢!它看起来可能是因为命名空间绑定。你能粘贴架构文件中的命名空间绑定吗? (看起来像'xmlns'的所有东西)。谢谢! –

+0

当谷歌搜索表明这可能是问题的根源的一些结果。 这是你在想什么? xs:schema xmlns =“urn:OECD:StandardAuditFile-Taxation/2.00”xmlns:xs =“http://www.w3.org/2001/XMLSchema”xmlns:doc =“urn:schemas-OECD: schema-extensions:documentation“targetNamespace =”urn:OECD:StandardAuditFile-Taxation/2.00“elementFormDefault =”qualified“attributeFormDefault =”unqualified“version =”2.00“id =”FAIA-T“>' – johankr