我有一个模式XSD文件,Main.xsd和Child.xsd。
Main.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" targetNamespace="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:import namespace="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" schemaLocation="Child.xsd"/>
<xsd:element name="Invoice">
<xsd:complexType>
<xsd:sequence>
<xsd:any namespace="##any" processContents="skip"/>
<xsd:element ref="cbc:UBLVersionID" minOccurs="0"/>
<xsd:element ref="cbc:CustomizationID"/>
<xsd:element ref="cbc:ProfileID"/>
<xsd:any namespace="##any" processContents="skip" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>Child.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:element name="UBLVersionID" type="cbc:UBLVersionIDType"/>
<xsd:element name="CustomizationID" type="cbc:CustomizationIDType"/>
<xsd:element name="ProfileID" type="cbc:ProfileIDType"/>
<xsd:complexType name="UBLVersionIDType">
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:anyAttribute namespace="##any" processContents="skip"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
<xsd:simpleType name="CustomizationIDType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="urn:cen.eu:en16931:2017#compliant#urn:fdc:nen.nl:nlcius:v1.0"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="ProfileIDType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="urn:fdc:peppol.eu:2017:poacc:billing:01:1.0"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>正如您在Main.xsd中所看到的,我们正在检查可选的UBLVersionID,CustomizationID和ProfileID,两者都是强制性的。xsd:any语句在UBLVersionID之前和ProfileID之后,跳过任何元素或字段,因为我们只需要检查在Main.xsd中定义的字段。Child.xsd定义了字段、规则等.
我的XSD对我拥有的所有2个XML都很好: A.xml,B.xml:
A.XML:有UBLExtensions和UBLVersionID
<Invoice xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ext:UBLExtensions xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2">
<ext:UBLExtension>
<ext:ExtensionContent>
<seef:SEEFExtensionWrapper xmlns:seef="urn:www.energie-efactuur.nl:profile:invoice:ver1.0">
<seef:UtilityConsumptionPoint>
<cbc:ID xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">871685920003767063</cbc:ID>
<seef:Address>
<cac:Address xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
<cbc:StreetName xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">Zuider IJdijk 46</cbc:StreetName>
<cbc:CityName xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">AMSTERDAM</cbc:CityName>
<cbc:PostalZone xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">1095 KN</cbc:PostalZone>
<cac:Country>
<cbc:IdentificationCode xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">NL</cbc:IdentificationCode>
</cac:Country>
</cac:Address>
</seef:Address>
</seef:UtilityConsumptionPoint>
</seef:SEEFExtensionWrapper>
</ext:ExtensionContent>
</ext:UBLExtension>
</ext:UBLExtensions>
<cbc:UBLVersionID xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">2.1</cbc:UBLVersionID>
<cbc:CustomizationID xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">urn:cen.eu:en16931:2017#compliant#urn:fdc:nen.nl:nlcius:v1.0</cbc:CustomizationID>
<cbc:ProfileID xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">urn:fdc:peppol.eu:2017:poacc:billing:01:1.0</cbc:ProfileID>
<cbc:ID xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">41014619807</cbc:ID>
<cbc:IssueDate xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">2021-11-10</cbc:IssueDate>
<cbc:DueDate xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">2021-11-24</cbc:DueDate>
<cbc:InvoiceTypeCode xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">380</cbc:InvoiceTypeCode>
<cbc:Note xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">Zuider IJdijk 46, 1095 KN AMSTERDAM; Voor de algemene voorwaarden, zie: https://www.liander.nl/algemene-voorwaarden.</cbc:Note>
<cbc:DocumentCurrencyCode xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">EUR</cbc:DocumentCurrencyCode>
<cbc:BuyerReference xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">28224654</cbc:BuyerReference>
</Invoice>B.XML:有UBLVersionID而没有UBLExtensions:
<Invoice xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<cbc:UBLVersionID xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">2.1</cbc:UBLVersionID>
<cbc:CustomizationID xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">urn:cen.eu:en16931:2017#compliant#urn:fdc:nen.nl:nlcius:v1.0</cbc:CustomizationID>
<cbc:ProfileID xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">urn:fdc:peppol.eu:2017:poacc:billing:01:1.0</cbc:ProfileID>
<cbc:ID xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">41014619807</cbc:ID>
<cbc:IssueDate xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">2021-11-10</cbc:IssueDate>
<cbc:DueDate xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">2021-11-24</cbc:DueDate>
<cbc:InvoiceTypeCode xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">380</cbc:InvoiceTypeCode>
<cbc:Note xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">Zuider IJdijk 46, 1095 KN AMSTERDAM; Voor de algemene voorwaarden, zie: https://www.liander.nl/algemene-voorwaarden.</cbc:Note>
<cbc:DocumentCurrencyCode xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">EUR</cbc:DocumentCurrencyCode>
<cbc:BuyerReference xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">28224654</cbc:BuyerReference>
</Invoice>我的C.XML正在产生验证错误,因为它没有UBLExtensions和UBLVersionID段。如您所见,模式中的xsd:any和UBLVersionID都是可选的。
C.XML:
<Invoice xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<cbc:CustomizationID xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">urn:cen.eu:en16931:2017#compliant#urn:fdc:nen.nl:nlcius:v1.0</cbc:CustomizationID>
<cbc:ProfileID xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">urn:fdc:peppol.eu:2017:poacc:billing:01:1.0</cbc:ProfileID>
<cbc:ID xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">41014619807</cbc:ID>
<cbc:IssueDate xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">2021-11-10</cbc:IssueDate>
<cbc:DueDate xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">2021-11-24</cbc:DueDate>
<cbc:InvoiceTypeCode xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">380</cbc:InvoiceTypeCode>
<cbc:Note xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">Zuider IJdijk 46, 1095 KN AMSTERDAM; Voor de algemene voorwaarden, zie: https://www.liander.nl/algemene-voorwaarden.</cbc:Note>
<cbc:DocumentCurrencyCode xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">EUR</cbc:DocumentCurrencyCode>
<cbc:BuyerReference xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">28224654</cbc:BuyerReference>
</Invoice>我做了很多尝试,我应该在我的模式中更改什么,这样它才能与我的所有3个xmls一起工作。请帮帮忙。
发布于 2021-12-02 02:54:45
错误信息是
名称空间'urn:oasis:names:specification:ubl:schema:xsd:Invoice-2‘中的元素’
‘在名称空间'urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2'.中具有无效的子元素'ProfileID’可能需要的元素列表:名称空间'urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2'.中的“UBLVersionID,CustomizationID”
这告诉您,要么是期望UBLVersionID,要么是因为UBLVersionID是可选的,所以它期待的是CustomizationID。这当然会让你觉得很奇怪,因为它实际上在那里。
如果您像下面这样再次添加CustomizationID,它实际上将验证。
<Invoice xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<cbc:CustomizationID xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">urn:cen.eu:en16931:2017#compliant#urn:fdc:nen.nl:nlcius:v1.0</cbc:CustomizationID>
<cbc:CustomizationID xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">urn:cen.eu:en16931:2017#compliant#urn:fdc:nen.nl:nlcius:v1.0</cbc:CustomizationID>
<cbc:ProfileID xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">urn:fdc:peppol.eu:2017:poacc:billing:01:1.0</cbc:ProfileID>
<cbc:ID xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">41014619807</cbc:ID>
<cbc:IssueDate xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">2021-11-10</cbc:IssueDate>
<cbc:DueDate xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">2021-11-24</cbc:DueDate>
<cbc:InvoiceTypeCode xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">380</cbc:InvoiceTypeCode>
<cbc:Note xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">Zuider IJdijk 46, 1095 KN AMSTERDAM; Voor de algemene voorwaarden, zie: https://www.liander.nl/algemene-voorwaarden.</cbc:Note>
<cbc:DocumentCurrencyCode xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">EUR</cbc:DocumentCurrencyCode>
<cbc:BuyerReference xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">28224654</cbc:BuyerReference>
</Invoice>这表明正在匹配<xsd:any namespace="##any" processContents="skip" />的CustomizationID。
您需要的是实际上定义其他字段,但作为可选字段。
Main.xml
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:seef="urn:www.energie-efactuur.nl:profile:invoice:ver1.0" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import schemaLocation=".\A1.xsd" namespace="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" />
<xs:import schemaLocation=".\A3.xsd" namespace="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
<xs:annotation>
<xs:appinfo>
<references xmlns="http://schemas.microsoft.com/BizTalk/2003">
<reference targetNamespace="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
<reference targetNamespace="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" />
<reference targetNamespace="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" />
<reference targetNamespace="urn:www.energie-efactuur.nl:profile:invoice:ver1.0" />
</references>
</xs:appinfo>
</xs:annotation>
<xs:element name="Invoice">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" ref="ext:UBLExtensions" />
<xs:element minOccurs="0" ref="cbc:UBLVersionID" />
<xs:element ref="cbc:CustomizationID" />
<xs:element ref="cbc:ProfileID" />
<xs:element ref="cbc:ID" />
<xs:element ref="cbc:IssueDate" />
<xs:element ref="cbc:DueDate" />
<xs:element ref="cbc:InvoiceTypeCode" />
<xs:element ref="cbc:Note" />
<xs:element ref="cbc:DocumentCurrencyCode" />
<xs:element ref="cbc:BuyerReference" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>Child1.xml
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:tns="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import schemaLocation=".\Child2.xsd" namespace="urn:www.energie-efactuur.nl:profile:invoice:ver1.0" />
<xs:element name="UBLExtensions">
<xs:complexType>
<xs:sequence>
<xs:element name="UBLExtension">
<xs:complexType>
<xs:sequence>
<xs:element name="ExtensionContent">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q1="urn:www.energie-efactuur.nl:profile:invoice:ver1.0" ref="q1:SEEFExtensionWrapper" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>Child2.xml
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:tns="urn:www.energie-efactuur.nl:profile:invoice:ver1.0" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="urn:www.energie-efactuur.nl:profile:invoice:ver1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import schemaLocation=".\Child3.xsd" namespace="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
<xs:import schemaLocation=".\Child4.xsd" namespace="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" />
<xs:element name="SEEFExtensionWrapper">
<xs:complexType>
<xs:sequence>
<xs:element name="UtilityConsumptionPoint">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q1="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" ref="q1:ID" />
<xs:element name="Address">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q2="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" ref="q2:Address" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>Child3.xml
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:tns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="ID" type="xs:unsignedLong" />
<xs:element name="StreetName" type="xs:string" />
<xs:element name="CityName" type="xs:string" />
<xs:element name="PostalZone" type="xs:string" />
<xs:element name="IdentificationCode" type="xs:string" />
<xs:element name="UBLVersionID" type="xs:decimal" />
<xs:element name="CustomizationID" type="xs:string" />
<xs:element name="ProfileID" type="xs:string" />
<xs:element name="IssueDate" type="xs:date" />
<xs:element name="DueDate" type="xs:date" />
<xs:element name="InvoiceTypeCode" type="xs:unsignedShort" />
<xs:element name="Note" type="xs:string" />
<xs:element name="DocumentCurrencyCode" type="xs:string" />
<xs:element name="BuyerReference" type="xs:unsignedInt" />
</xs:schema>Child4.xml
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:tns="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import schemaLocation=".\Child3.xsd" namespace="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
<xs:element name="Address">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q1="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" ref="q1:StreetName" />
<xs:element xmlns:q2="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" ref="q2:CityName" />
<xs:element xmlns:q3="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" ref="q3:PostalZone" />
<xs:element name="Country">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q4="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" ref="q4:IdentificationCode" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>https://stackoverflow.com/questions/70105485
复制相似问题