针对 XSD 验证 XML 时出错 [英] Error while validating XML against XSD
问题描述
我有一个简单的 XML 文件,我想根据 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:
发现以元素实体"开头的无效内容.应为{Entities}"之一.
Invalid content was found starting with element 'Entities'. One of '{Entities}' is expected.
这是 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>
以及 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="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="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? ;)
推荐答案
{目标命名空间}
如果 form
存在并且它的实际值是 qualified
,或者如果 form
不存在并且 <
祖先上的 elementFormDefault
的 em>实际值 是 qualified
,那么 实际值父
元素信息项的targetNamespace
[attribute] 的em>,如果没有,则不存在,否则缺席.
If form
is present and its actual value is qualified
, or if form
is absent and the actual value of elementFormDefault
on the <schema>
ancestor is qualified
, then the actual value of the targetNamespace
[attribute] of the parent <schema>
element information item, or absent if there is none, otherwise absent.
由于elemeFormDefault
的默认值是unqualified
,除非另有说明,本地元素必须是unqualified.
Since the default value of elemeFormDefault
is unqualified
, unless otherwise specified the local elements must be unqualified.
自从您设置了 xmlns="http://schemas.testxyzxyz.de/xyz/BusinessModel"
后,Entities
就成为合格的.解决方法是将 elementFormDefault="qualified"
设置为 @polishchuk 所写.
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.
这篇关于针对 XSD 验证 XML 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!