gpt4 book ai didi

xml - 如何使用 xmllint 来验证内部指定的 xsd?

转载 作者:数据小太阳 更新时间:2023-10-29 02:09:55 25 4
gpt4 key购买 nike

我知道您可以使用 xmllint 命令来验证 local xsd files ,或针对 xsd 网络文件位置,但我想做的是指示 xmllint 根据其“内部指定”xsd 验证 XML 文件,例如此 XML 指定 XSD 位置:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ord-archive:XXX xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://somewhere/something.xsd">
...

有没有什么方法可以使用 xmllint 并针对其内部指定的 schemaLocation 指定“验证”?

最佳答案

xsi:schemaLocation 应该包含一个 URI 列表,在语义上两两分组。每个出现在奇数位置的 URI 指定一个命名空间,出现在下一个偶数位置的 URI 指定用于此命名空间的模式的位置提示。位置提示可以是本地的或远程的。

这是一个包含三个命名空间的示例:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ord-archive:XXX
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:ord-archive="http://www.example.com/namespace"
xmlns:prefix="http://www.example.com/another-namespace"
xmlns:other-prefix="http://www.example.com/and-another-namespace"

xsi:schemaLocation="
http://www.example.com/namespace
http://somewhere.example.com/something.xsd
http://www.example.com/another-namespace
some-relative-path-to-a-directory/some-local-file.xsd
http://www.example.com/and-another-namespace
file:///some-absolute-path-to-a-directory/some-local-file.xsd">

<!-- the document itself, which contains elements in the three
namespaces, referenced with the bound prefixes. -->
</ord-archive:XXX>

XML Schema 规范给验证引擎留下了一定程度的自由,因此理论上它们可能会或可能不会遵循提示,它们可能会为某些 namespace 使用缓存版本等。但是,在实践中,大多数验证引擎将使用您的提示或提供特定于实现的方式来控制它们的行为。

问题中链接下给出的示例使用 xsi:noNamespaceSchemaLocation,其中包含没有目标命名空间的模式的位置提示。

关于xml - 如何使用 xmllint 来验证内部指定的 xsd?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44555678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com