如何从XML文件引用本地XSD?

时间:2016-07-08 10:08:57

标签: xml xsd xsd-validation xml-validation

我想编写一个简单的XML文件,其中包含位于我计算机上同一本地目录中的自定义xsd文件。我不明白文件开头的必要语法(我已经google了但是XSD教程似乎关注的是元素定义而不是xsd:schema)。

我的sys_params.xsd开始了:

<xsd:schema xmlns:xsd="http://www.w3.org/1999/XMLSchema">

<xsd:element     name="shipOrder" type="order"/>

我的sys_params.xml开始了:

<shiporder orderid="889923"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com sys_params.xsd"

<orderperson>John Smith</orderperson>

我的XML在xml上报告此验证错误:

  

错误架构文档'sys_params.xsd'具有不同的目标命名空间   来自实例文档“http://www.w3schools.com

中指定的那个

毫无疑问,我的代码是错误的,但我需要一些帮助来纠正它。

1 个答案:

答案 0 :(得分:7)

更改

xsi:schemaLocation="http://www.w3schools.com sys_params.xsd"

xsi:noNamespaceSchemaLocation="sys_params.xsd"

因为您的XML不在命名空间中。请参阅我在评论中提供的链接以获取更多详细信息。