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

How to reference local XSD from XML file?

我想编写一个简单的 XML 文件,其中包含位于我计算机上同一本地目录中的自定义 xsd 文件。我不明白文件开头的必要语法(我用谷歌搜索过,但 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 上报告此验证错误:

Error schema document 'sys_params.xsd' has different target namespace from the one specified in instance document 'http://www.w3schools.com'

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

改变

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

xsi:noNamespaceSchemaLocation="sys_params.xsd"

因为您的 XML 不在命名空间中。

另请参阅: