我发现这个问题有点帮助但并不完全。
XSD - how to allow elements in any order any number of times?
我有以下xml,我想对XSD进行验证。
XSD有效,但我在XML中遇到错误。它说Unexpected element FirmAgent in element <element>. No further element expected
我的要求是:
<element>
可多次出现<element>
内的元素可能会多次出现,有些是可选的,但所有元素都应按任意顺序排列我尽力做到这一点。 这是XML:
<?xml version="1.0" encoding="UTF-8"?>
<archive-elements xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="update1.xsd">
<element type="1">
<AdminDistrict>Tes4tveien</AdminDistrict>
<FirmAgent>Testv12eien</FirmAgent>
<UpdateByPersNum>Te5stveien</UpdateByPersNum>
<AttachedFilesListNameInsurance>Test67veien</AttachedFilesListNameInsurance>
<AttachedFilesListURLInsurance>Testv2ien</AttachedFilesListURLInsurance>
<Saksnummer>asdf</Saksnummer>
<StatusSign>asdf</StatusSign>
<Status>asdf</Status>
<LocationNr>3</LocationNr>
<LineNr>01</LineNr>
<TariffNr>501</TariffNr>
<CompanyName>Test Person</CompanyName>
<OrganizationNr>12345678901</OrganizationNr>
<Email>test@ifasdf.no</Email>
<UpdateDate>09/30/2011 22:09</UpdateDate>
<ArchiveType>Godt voksen</ArchiveType>
<ArchiveApplyFor>Godt voksen Med sykdom</ArchiveApplyFor>
<TypeOfUpdate>1</TypeOfUpdate>
<DocID>CF26F4222B84991DC125791B006F333E</DocID>
<PolicyNr>4664735</PolicyNr>
<Form>Update1</Form>
<UpdatedBy>12345678901</UpdatedBy>
<Status>Effektuert</Status>
<BehandletKde> </BehandletKde>
<Status>Effektuert</Status>
<BehandletKde> sdf</BehandletKde>
<LabourCosts>123</LabourCosts>
<SumInsured>asdf</SumInsured>
<oldSumInsured>50.000</oldSumInsured>
<OtherChanges>Bla bla</OtherChanges>
<Coverage>asdf</Coverage>
<oldCoverage>yrke med lav risiko</oldCoverage>
<ValidFrom>01.10.11</ValidFrom>
<County>asdf</County>
<oldCounty>aasdf</oldCounty>
<LocatioName>asdf</LocatioName>
<oldLocatioName>Testveien 1</oldLocatioName>
<Question1>asdf</Question1>
<LabourCosts>asdf</LabourCosts>
<RefNum>asdf</RefNum>
<RegisterDate>sadf</RegisterDate>
<OpplastDat>asdf</OpplastDat>
<SumInsuredInHundred>asdf</SumInsuredInHundred>
<FraTms>asdf</FraTms>
<ValidFromType>sadfas2</ValidFromType>
<Transkode>asdf</Transkode>
<Period>asdf</Period>
<BehandlerSign>FCO</BehandlerSign>
</element>
<element type="1">
<AdminDistrict>Tes4tveien</AdminDistrict>
<FirmAgent>Testv12eien</FirmAgent>
<UpdateByPersNum>Te5stveien</UpdateByPersNum>
<AttachedFilesListNameInsurance>Test67veien</AttachedFilesListNameInsurance>
<AttachedFilesListURLInsurance>Testv2ien</AttachedFilesListURLInsurance>
<Saksnummer>asdf</Saksnummer>
<StatusSign>asdf</StatusSign>
<Status>asdf</Status>
<LocationNr>3</LocationNr>
<LineNr>01</LineNr>
<TariffNr>501</TariffNr>
<CompanyName>Test Person</CompanyName>
<OrganizationNr>12345678901</OrganizationNr>
<Email>test@iasdff.no</Email>
<UpdateDate>09/30/2011 22:09</UpdateDate>
<ArchiveType>Godt voksen</ArchiveType>
<ArchiveApplyFor>Godt voksen Med sykdom</ArchiveApplyFor>
<TypeOfUpdate>1</TypeOfUpdate>
<DocID>CF26F4222B84991DC125791B006F333E</DocID>
<PolicyNr>4664735</PolicyNr>
<Form>Update1</Form>
<UpdatedBy>12345678901</UpdatedBy>
<LabourCosts>123</LabourCosts>
<SumInsured>asdf</SumInsured>
<oldSumInsured>50.000</oldSumInsured>
<OtherChanges>Bla bla</OtherChanges>
<Coverage>asdf</Coverage>
<oldCoverage>yrke med lav risiko</oldCoverage>
<ValidFrom>01.10.11</ValidFrom>
<County>asdf</County>
<oldCounty>aasdf</oldCounty>
<LocatioName>asdf</LocatioName>
<oldLocatioName>Testveien 1</oldLocatioName>
<Question1>asdf</Question1>
<LabourCosts>asdf</LabourCosts>
<RefNum>asdf</RefNum>
<RegisterDate>sadf</RegisterDate>
<OpplastDat>asdf</OpplastDat>
<SumInsuredInHundred>asdf</SumInsuredInHundred>
<FraTms>asdf</FraTms>
<ValidFromType>sadfas2</ValidFromType>
<Transkode>asdf</Transkode>
<Period>asdf</Period>
<BehandlerSign>FCO</BehandlerSign>
</element>
</archive-elements>
这是XSD
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="archive-elements">
<xs:complexType>
<xs:sequence>
<xs:element name="element" maxOccurs="unbounded">
<xs:complexType>
<xs:choice>
<xs:element name="AdminDistrict" type="xs:string"/>
<xs:element name="FirmAgent" type="xs:string"/>
<xs:element name="UpdateByPersNum" type="xs:string"/>
<xs:element name="AttachedFilesListNameInsurance" type="xs:string"/>
<xs:element name="AttachedFilesListURLInsurance" type="xs:string"/>
<xs:element name="Saksnummer" type="xs:string"/>
<xs:element name="StatusSign" type="xs:string"/>
<xs:element name="LocationNr" type="xs:string" />
<xs:element name="LineNr" type="xs:string"/>
<xs:element name="TariffNr" type="xs:string"/>
<xs:element name="CompanyName" type="xs:string"/>
<xs:element name="OrganizationNr" type="xs:string"/>
<xs:element name="Email" type="xs:string"/>
<xs:element name="UpdateDate" type="xs:string"/>
<xs:element name="ArchiveType" type="xs:string"/>
<xs:element name="ArchiveApplyFor" type="xs:string"/>
<xs:element name="TypeOfUpdate">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="DocID" type="xs:string"/>
<xs:element name="PolicyNr" type="xs:string"/>
<xs:element name="Form">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Update1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="UpdatedBy" type="xs:string"/>
<xs:element name="Status" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="BehandletKde" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="SumInsured" type="xs:string"/>
<xs:element name="oldSumInsured" type="xs:string"/>
<xs:element name="OtherChanges" type="xs:string"/>
<xs:element name="Coverage" type="xs:string"/>
<xs:element name="oldCoverage" type="xs:string"/>
<xs:element name="ValidFrom" type="xs:string"/>
<xs:element name="County" type="xs:string"/>
<xs:element name="oldCounty" type="xs:string"/>
<xs:element name="LocatioName" type="xs:string"/>
<xs:element name="oldLocatioName" type="xs:string"/>
<xs:element name="Question1" type="xs:string"/>
<xs:element name="LabourCosts" type="xs:string" minOccurs="0"/>
<xs:element name="RefNum" type="xs:string" minOccurs="0"/>
<xs:element name="RegisterDate" type="xs:string" minOccurs="0"/>
<xs:element name="OpplastDat" type="xs:string" minOccurs="0"/>
<xs:element name="SumInsuredInHundred" type="xs:string" minOccurs="0"/>
<xs:element name="FraTms" type="xs:string" minOccurs="0"/>
<xs:element name="ValidFromType" type="xs:string" minOccurs="0"/>
<xs:element name="Transkode" type="xs:string" minOccurs="0"/>
<xs:element name="Period" type="xs:string" minOccurs="0"/>
<xs:element name="BehandlerSign" type="xs:string" minOccurs="0"/>
</xs:choice>
<xs:attribute name="type" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
答案 0 :(得分:0)
在这个问题和你的问题中面临的问题基本上就是你说的,我想要一个xsd用于旁边没有结构的东西......
如果你使用xs:all,那么你可以按任意顺序拥有内部元素,0到1次。 (对于强制/可选,使用minOccurs为0或1)。 如果你想要一个重复元素,那么你需要一个节点来绑定它们,例如订单和订单,虽然在您的示例中看不到。
xs:choice会解决尽可能多的问题,它很脆弱,通常都是一个解析的git。
我正在认真考虑合理化你想要描述的xml,你走的路是一无所有。
你可以使用xs:any来让你离开,并开始努力坚定。