Try*_*ipt 2 xml xsd xml-validation xsd-validation
我对 XML 非常陌生,目前准备使用 Ineasysteps。我不断从解析器那里得到同样的问题
5:元素“xsd:schema”的前缀“xsd”未绑定。
这是 hello.xml:
<?xml version = "1.0" encoding = "UTF-8" ?>
<!-- XML in easy steps - Page 82. -->
<doc xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation = "hello.xsd" >
<msg>Hello World</msg>
</doc>
Run Code Online (Sandbox Code Playgroud)
这是 hello.xsd 文档
<?xml version="1.0" encoding = "UTF-8" ?>
<!-- XML in easy steps - Page 84. -->
<xsd:schema>
<!-- DECLARE ELEMENTS. -->
<!-- Simple types. -->
<xsd:element name="msg" type="xsd:string"/>
<!-- Complex types. -->
<xsd:element name="doc" type="docType"/>
<!-- DEFINE STRUCTURE. -->
<xsd:complexType name="docType">
<xsd:sequence>
<xsd:element ref="msg"/>
</xsd:sequence>
</xsd:complexType
Run Code Online (Sandbox Code Playgroud)
命名空间前缀xsd必须在使用之前定义。这甚至适用于XML 架构 (XSD) 组件常用的众所周知的xsd(或) 前缀。xs
要消除该错误,xsd请通过添加来定义命名空间前缀
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
Run Code Online (Sandbox Code Playgroud)
像xsd:schema这样的根元素:
<?xml version="1.0" encoding = "UTF-8" ?>
<!-- XML in easy steps - Page 84. -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- DECLARE ELEMENTS. -->
<!-- Simple types. -->
<xsd:element name="msg" type="xsd:string"/>
<!-- Complex types. -->
<xsd:element name="doc" type="docType"/>
<!-- DEFINE STRUCTURE. -->
<xsd:complexType name="docType">
<xsd:sequence>
<xsd:element ref="msg"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8161 次 |
| 最近记录: |