XML from XSD error Invalid content was found
I am trying to create an XML file based on an XSD schema definition. The schema definition is found in the following link
Schema- http://xmlgw.companieshouse.gov.uk/v1-0/schema/forms/CompanyIncorporation-v2-6.xsd
And my XML looks like this:
<?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>
But this will result in a validation error,
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.
source to share
You seem to be missing a few requirements.
A document type CompanyIncorporationType
that is just an element sequence
. With sequence
all the elements in it must be specified, unless minOccurs
not set to 0.
The schema element
xsd:sequence
specifies that the incoming set of elements must occur in the given order and according to the specified minimum and maximum repetition values. (The default is 1.)
Since the error occurs when <SameDay>
, look at all the elements (same levels) defined in the xsd between <xs:element name="RestrictedArticles">
and<xs:element name="SameDay">
-
<xs:element name="Appointment" maxOccurs="unbounded">
- REQUIRED -
<xs:element name="StatementOfCapital" type="StatementOfCapitalType" minOccurs="0"/>
- Not required -
<xs:element name="Subscribers" type="SubscriberPersonType" minOccurs="0" maxOccurs="unbounded">
- Not required -
<xs:element name="Guarantors" type="GuarantorType" minOccurs="0" maxOccurs="unbounded">
- Not required -
<xs:element name="Authoriser">
- REQUIRED
So...
You are missing two items <Appointment>
and <Authorizer>
before<SameDay>
However, it is often helpful to create an IDE (or some xml tool) to create the implant xml shema. For example, with Eclipse, it will create a minimal bare bones skeleton to test for xsd.
Here is a file generated (by Eclipse) that has a minimum xml minimum to check
<?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>
UPDATE
To explain the elements you see inside <Appointment>
and <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>
You can see that it <Appointment>
has sequence
- <Authentication>
exactly three times, and a choice
, between <Director>
, <Secretary>
or <Member>
. You will need to sort the contents of the xsd to see the type requirements for these elements.
<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>
You can see that <Authoriser>
you want to a single choice: <Agent>
, <Member>
, <Solicitor>
or <Subscriber>
. You will need to sort the contents of the xsd to see the type requirements for these elements.
source to share