我正在尝试基于XSD架构定义创建XML文件,该架构定义在以下链接中找到
架构-http://xmlgw.companieshouse.gov.uk/v1-0/schema/forms/CompanyIncorporation-v2-6.xsd
我的XML如下
<?xml version="1.0" encoding="UTF-8"?>
<CompanyIncorporation xmlns="http://xmlgw.companieshouse.gov.uk" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlgw.companieshouse.gov.uk http://xmlgw.companieshouse.gov.uk/v2-1/schema/forms/CompanyIncorporation-v2-6.xsd">
<CompanyType>BYSHR</CompanyType>
<CountryOfIncorporation>EW</CountryOfIncorporation>
<RegisteredOfficeAddress>
<Premise>38</Premise>
<Street>Vaughan Road</Street>
<Thoroughfare>Pentwyn</Thoroughfare>
<PostTown>Harrow</PostTown>
<Country>GB-ENG</Country>
<Postcode>HA1 4EE</Postcode>
</RegisteredOfficeAddress>
<Articles>BESPOKE</Articles>
<RestrictedArticles>false</RestrictedArticles>
<SameDay>false</SameDay>
<SameName>false</SameName>
<NameAuthorisation>false</NameAuthorisation>
</CompanyIncorporation>
但是当我验证它时会产生一个错误,
Not valid.
Error - Line 15, 18: org.xml.sax.SAXParseException; lineNumber: 15; columnNumber: 18;
cvc-complex-type.2.4.a: Invalid content was found starting with element 'SameDay'. One
of '{"http://xmlgw.companieshouse.gov.uk":Appointment}' is expected.
您似乎缺少一些要求。
文档类型CompanyIncorporationType
只是sequence
元素的一个。使用sequence
,必须指定其中的所有元素,除非minOccurs
设置为0。
schema元素
xsd:sequence
定义了封闭的元素集应按照给定的顺序并根据指定的最小和最大重复计数出现。(两者的默认值为1。)
由于错误发生在<SameDay>
,请查看<xs:element name="RestrictedArticles">
和之间的xsd中定义的所有(相同级别)元素。<xs:element name="SameDay">
<xs:element name="Appointment" maxOccurs="unbounded">
-必填
<xs:element name="StatementOfCapital" type="StatementOfCapitalType" minOccurs="0"/>
-不需要
<xs:element name="Subscribers" type="SubscriberPersonType" minOccurs="0" maxOccurs="unbounded">
-不需要
<xs:element name="Guarantors" type="GuarantorType" minOccurs="0" maxOccurs="unbounded">
-不需要
<xs:element name="Authoriser">
-必填
所以...
您缺少两个要素,<Appointment>
并且<Authorizer>
之前<SameDay>
也就是说,使用IDE(或某些xml工具)创建xml shema实现通常会有所帮助。例如,使用Eclipse,它将创建裸露的骨骼最小骨架以针对xsd进行验证。
这是由Eclipse创建的文件,该文件对xml进行验证具有最低要求
<?xml version="1.0" encoding="UTF-8"?>
<CompanyIncorporation ... >
<CompanyType>PLC</CompanyType>
<CountryOfIncorporation>EW</CountryOfIncorporation>
<RegisteredOfficeAddress>RegisteredOfficeAddress</RegisteredOfficeAddress>
<Appointment>
<Authentication>Authentication</Authentication>
<Authentication>Authentication</Authentication>
<Authentication>Authentication</Authentication>
<Director />
</Appointment>
<Authoriser>
<Agent>
<Person>Person</Person>
<Authentication />
<Authentication />
<Authentication />
<Address>Address</Address>
</Agent>
</Authoriser>
<SameDay>true</SameDay>
</CompanyIncorporation>
更新
为了解释您在<Appointment>
和中看到的元素<Authoriser>
:
<Appointment>
<xs:element name="Appointment" maxOccurs="unbounded">
<xs:annotation>
<xs:documentation>Proposed officers</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="Authentication" type="PersonalAttributeType" minOccurs="3" maxOccurs="3"/>
<xs:choice>
<xs:element name="Director">
<xs:complexType>
<xs:complexContent>
<xs:extension base="DirectorAppointmentType"/>
</xs:complexContent>
</xs:complexType>
</xs:element>
<xs:element name="Secretary" type="SecretaryAppointmentType"/>
<xs:element name="Member" type="MemberAppointmentType"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
你可以看到<Appointment>
有一个sequence
-<Authentication>
正好三次,和一choice
之间<Director>
,<Secretary>
或<Member>
。您将必须对xsd进行排序才能真正看到这些元素类型的要求
<Authoriser>
<xs:element name="Authoriser">
<xs:complexType>
<xs:choice>
<xs:element name="Agent" type="AgentType">
</xs:element>
<xs:element name="Solicitor" type="AuthoriserType">
</xs:element>
<xs:element name="Member" type="AuthoriserType">
</xs:element>
<xs:element name="Subscribers">
<xs:complexType>
<xs:sequence>
<xs:element name="Subscriber" type="AuthoriserType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
你可以看到<Authoriser>
,需要一个单一的任何一种选择<Agent>
,<Member>
,<Solicitor>
,或<Subscriber>
。您将必须对xsd进行排序才能真正看到这些元素类型的要求
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句