Error while validating XML against XSD
I got a simple XML file that I want to validate against an XSD. When I validate with some random validator, I always get the following error:
Invalid content was found starting with element 'Entities'. One of '{Entities}' is expected.
Here's the XML:
<BusinessModel xmlns="http://schemas.testxyzxyz.de/xyz/BusinessModel" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Entities>
<Entity Name="Customer">
<Attribute Name="Forename" Type="String" />
<Attribute Name="Surname" Type="String" />
<Attribute Name="Birthday" Type="Date" />
</Entity>
</Entities>
</BusinessModel>
As well as the XSD:
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://schemas.testxyzxyz.de/xyz/BusinessModel"
xmlns="http://schemas.testxyzxyz.de/xyz/BusinessModel">
<xsd:element name="BusinessModel" type="BusinessModelType" />
<xsd:complexType name="BusinessModelType">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="Entities" type="EntitiesType" />
</xsd:choice>
</xsd:complexType>
<xsd:complexType name="EntitiesType">
<xsd:sequence>
<xsd:element name="Entity" type="EntityType" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="AttributeType">
<xsd:attribute name="Name" type="xs开发者_运维百科d:string" use="required" />
<xsd:attribute name="Type" type="xsd:string" use="required" />
</xsd:complexType>
<xsd:complexType name="EntityType">
<xsd:sequence>
<xsd:element name="Attribute" type="AttributeType" maxOccurs="unbounded" minOccurs="1" />
</xsd:sequence>
<xsd:attribute name="Name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:schema>
Looking for that issue since hours, and I still don't find an error. Can you spot me the right direction? ;)
XML Representation of Element Declaration Schema Components:
{target namespace}
If
form
is present and its actual value isqualified
, or ifform
is absent and the actual value ofelementFormDefault
on the<schema>
ancestor isqualified
, then the actual value of thetargetNamespace
[attribute] of the parent<schema>
element information item, or absent if there is none, otherwise absent.
Since the default value of elemeFormDefault
is unqualified
, unless otherwise specified the local elements must be unqualified.
Since you set the xmlns="http://schemas.testxyzxyz.de/xyz/BusinessModel"
, the Entities
became qualified.
The fix is to set elementFormDefault="qualified"
as @polishchuk wrote.
Try this schema:
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://schemas.testxyzxyz.de/xyz/BusinessModel" xmlns:b="http://schemas.testxyzxyz.de/xyz/BusinessModel">
<xsd:element name="BusinessModel" type="b:BusinessModelType" />
<xsd:complexType name="BusinessModelType">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="Entities" type="b:EntitiesType" />
</xsd:choice>
</xsd:complexType>
<xsd:complexType name="EntitiesType">
<xsd:sequence>
<xsd:element name="Entity" type="b:EntityType" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="AttributeType">
<xsd:attribute name="Name" type="xsd:string" use="required" />
<xsd:attribute name="Type" type="xsd:string" use="required" />
</xsd:complexType>
<xsd:complexType name="EntityType">
<xsd:sequence>
<xsd:element name="Attribute" type="b:AttributeType" maxOccurs="unbounded" minOccurs="1" />
</xsd:sequence>
<xsd:attribute name="Name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:schema>
精彩评论