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

rog*_*ack 5 xml validation xsd xmllint

我知道您可以使用该xmllint命令来针对本地 xsd 文件或针对 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">
 ...
Run Code Online (Sandbox Code Playgroud)

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

Ghi*_*rny 1

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>
Run Code Online (Sandbox Code Playgroud)

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

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