开发者

How to include DTD in a XML document

How do I include DTD in a XML document开发者_开发知识库. Please provide me a sample. Thanks


use the DOCTYPE declaration: <!DOCTYPE root-element SYSTEM "filename">

http://www.w3schools.com/dtd/dtd_intro.asp

http://www.w3schools.com/tags/tag_doctype.asp


I prefer to use the XML classes in the System.Xml.Linq namespace myself because they're much easier to work with. It's very easy to create a doctype object like this:

using System.Xml.Linq;

// ...

XDocumentType docType = new XDocumentType("myDoctypeName", null, "myown.dtd", null);

You can then build an XML document by creating a root XElement and wrapping the root and doctype in an XDocument like so:

XDocument doc = new XDocument(docType, rootElement);


If you are talking about programmatically adding it in code on an XmlDocument in C# then you might want to look at the XmlDocument.CreateDocumentType Method.

If not, you might want to expand on what it is you are after exactly.


e.g. for using global variables across several files

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration SYSTEM "sample.dtd">
<myxml>
<node1>&testval;</node1>
</myxml>

sample.dtd:
<!ENTITY testval "1" >

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜