我有几个 XSD 并尝试根据它们验证我的 XML:
第一个(在 (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>
第二个(有一些递归)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>
具有递归名称的元素可以具有属性 nm_service,其值在 common.xsd 中定义
但是当我尝试验证时
<?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>
我收到错误 qname 值未解析为 (n) 简单类型定义
<xsd:attribute name="nm_service" type="p:nm_service"></xsd:attribute>
任何帮助,将不胜感激。谢谢
注意:您发布的 XSD 似乎与您报告的错误消息不一致。
要修复的两个主要错误:
xsd:schema
它在不应该出现的地方是自关闭的。val_1
应该是vl_1
.总之,以下 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>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句