[英]XML vs XSD verification
I have a several XSD and try to verify my XML against them as: 我有几个XSD,并尝试针对它们验证我的XML:
First one (with nm_service values in (vl_1, vl_2)) common.xsd 第一个(在(vl_1,vl_2)中具有nm_service值) common.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://tii.ru/crmcom/uiconf/common"/>
<xsd:simpleType name="nm_service">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="vl_1" />
<xsd:enumeration value="vl_2" />
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
Second one (with some recursion) recur.xsd 第二个(有些递归) recur.xsd
<?xml version="1.0" encoding="utf-8" ?>
<!--XML Schema generated by QTAssistant/XML Schema Refactoring (XSR) Module
(http://www.paschidev.com) -->
<xsd:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:p="http://tii.ru/crmcom/uiconf/common">
<xsd:import namespace="http://tii.ru/crmcom/uiconf/common"
schemaLocation="common.xsd" />
<xsd:element name="object">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="recursive" minOccurs="0" />
<xsd:element ref="center" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="recursive">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="recursive" minOccurs="0" />
<xsd:element ref="center" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="nm_service" type="p:nm_service"></xsd:attribute>
</xsd:complexType>
</xsd:element>
<xsd:element name="center" />
</xsd:schema>
Element with the name of recursive can have attribute nm_service with values defined in common.xsd 名称为递归的元素可以具有属性nm_service,其值在common.xsd中定义
But when I try to validate 但是当我尝试验证
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<object xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/XMLSchema.xsd">
<recursive>
<recursive nm_service="val_1" >
<recursive>
<center>
<recursive>
</recursive>
</center>
</recursive>
</recursive>
</recursive>
</object>
I got error The qname values does not resolve to a(n) simple type definition at 我收到错误qname值无法解析为a(n)简单类型定义
<xsd:attribute name="nm_service" type="p:nm_service"></xsd:attribute>
Any help would be appreciated. 任何帮助,将不胜感激。 Thanks
谢谢
Note : It seems that you may have posted XSDs inconsistent with the error message you reported. 注意 :似乎您发布的XSD与您报告的错误消息不一致。
Two main errors to fix: 要解决的两个主要错误:
xsd:schema
is self-closed where it shouldn't be. xsd:schema
在不应该关闭的地方是自动关闭的。 val_1
should be vl_1
. val_1
应该是vl_1
。 Altogether, the following XSDs will validate your XML successfully: 总共,以下XSD将成功验证XML:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://tii.ru/crmcom/uiconf/common">
<xsd:simpleType name="nm_service">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="vl_1" />
<xsd:enumeration value="vl_2" />
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema.xsd"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:p="http://tii.ru/crmcom/uiconf/common">
<xsd:import namespace="http://tii.ru/crmcom/uiconf/common"
schemaLocation="common.xsd" />
<xsd:element name="object">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="recursive" minOccurs="0" />
<xsd:element ref="center" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="recursive">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="recursive" minOccurs="0" />
<xsd:element ref="center" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="nm_service" type="p:nm_service"></xsd:attribute>
</xsd:complexType>
</xsd:element>
<xsd:element name="center" />
</xsd:schema>
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<object xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://tempuri.org/XMLSchema.xsd"
xsi:schemaLocation="http://tempuri.org/XMLSchema.xsd recur.xsd">
<recursive>
<recursive nm_service="vl_1" >
<recursive>
<center>
<recursive>
</recursive>
</center>
</recursive>
</recursive>
</recursive>
</object>
You are missing namespace prefixes, for example 您缺少名称空间前缀,例如
<xsd:element ref="recursive" minOccurs="0" />
should be 应该
<xsd:element ref="p:recursive" minOccurs="0" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.