Local XML validation with DTD or XSD using a relative path?

我怕爱的太早我们不能终老 提交于 2019-12-06 06:18:35

问题


An XML file can be defined and validated with an Document Type Description (DTD) or XML Schema (xsd) as follows:

<?xml version='1.0' encoding='UTF-8'?>
<annotation xmlns="http://www.xyz.com"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.xyz.com
    file:system.xsd" >

or

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE annotation SYSTEM "http://www.xyz.de/system.dtd">

Both ways define a URL where the DTD or XSD is found. Is there a way to give a relative or local path? So I can store them allong with the XML files instead of relying on a server?


回答1:


It's easy. Just put the relative location of the file like

<?xml version='1.0' encoding='UTF-8'?>
<annotation xmlns="http://www.xyz.com" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.xyz.com ./system.xsd" >


来源:https://stackoverflow.com/questions/14711569/local-xml-validation-with-dtd-or-xsd-using-a-relative-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!