Validate xml via dtd, different directory for dtd

筅森魡賤 提交于 2019-12-04 09:03:11

Declare in the Xml file the association with the DTD:

Example in case the dtd is stored in a remote server:

<!DOCTYPE Catalog PUBLIC "abc/Catalog" "http://xyz.abc.org/dtds/catalog.dtd">

Take a look at that wiki page and at that site for more options and information about Xml files and DTD association.

Example in case the dtd is placed locally (SYSTEM):

How to reference a DTD from a document:

Assuming the top element of the document is spec and the dtd is placed in the file mydtd in the subdirectory dtds of the directory from where the document were loaded:

<!DOCTYPE spec SYSTEM "dtds/mydtd">

Notes:

The system string is actually an URI-Reference (as defined in RFC 2396) so you can use a full URL string indicating the location of your DTD on the Web. This is a really good thing to do if you want others to validate your document. It is also possible to associate a PUBLIC identifier (a magic string) so that the DTD is looked up in catalogs on the client side without having to locate it on the web. A DTD contains a set of element and attribute declarations, but they don't define what the root of the document should be. This is explicitly told to the parser/validator as the first element of the DOCTYPE declaration.

(Excerpt from here)

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