使用系统XSD进行XML离线验证

3
当我们将xsd放入xsi:schemaLocation中时,它是否会从互联网下载xsd并验证xml?
如果是这种情况,我希望通过下载xsd进行离线验证。我该如何做到这一点?
我知道如何为DTD进行离线验证,但不确定如何处理xsd。
对于DTD,我目前正在执行以下操作:
<!DOCTYPE struts-config SYSTEM "struts-config_1_1.dtd">

我可以做类似这样的事情吗?

来自

<!-- beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd"-->

to

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
                           file://spring-beans-3.0.xsd
                           http://www.springframework.org/schema/context
                           file://spring-context-3.0.xsd">

编辑:

看起来我错了。当在jar文件中找不到dtd / xsd时,spring只会连接到互联网。我拔掉了互联网插头,发现应用程序可以正常工作。

此外,来源:https://forum.hibernate.org/viewtopic.php?f=1&t=949031

很抱歉给您带来麻烦和错误的问题。


它能下载吗?“它”是谁?不同的软件行为不同。如果不知道“它”是什么,我们就无法告诉您您的软件如何行为。 - Michael Kay
@MichaelKay 对不起,我问错了问题。它可以下载并且离线工作得很好。 - user982733
1个回答

0

可以的;但需要确保URI对于你的方案是有效的(在你的情况下是file://,在Windows上更像是file://c:/something/my.xsd)。

确保所有XSD文件也存储在本地,并且所有XSD文件之间的引用都是正确的。


我可以使用相对路径 file://my.xsd 而不是绝对路径 file://c:/something/my.xsd 吗? - user982733
1
我不会使用file://作为相对路径;只需使用./my.xsd(不要为相对路径使用方案,这就是我的意思)。 - Petru Gardea

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接