How to create linq info for xml with DTD link?
I need to generate xml-infoset, but the infoset should contain a reference to the client's DTD. Desired output should contain this DTD reference
<!DOCTYPE AutoApplication SYSTEM "http://www.clientsite.com/public/DTD/autoappV1-3-level2.dtd">
This link is directly tied to the xml declaration. Neither XProcessingInstruction nor XDeclaration does the job, is there another type I need to use?
+2
source to share
2 answers
you need to add your dtd using XDocumentType object. see here for more information. It should be noted that xlinq has quite limited handling for DTDs though ( see Msdn ).
some sample code ....
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Linq;
public class MainClass
{
public static void Main()
{
XDocument xDocument = new XDocument();
XDocumentType documentType = new XDocumentType("Books", null, "Books.dtd", null);
xDocument.Add(documentType, new XElement("Books"));
Console.WriteLine(xDocument);
}
}
+2
source to share
For this snippet, xml.
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE AutoApplication SYSTEM "http://www.clientsite.com/public/DTD/autoappV1-3-level2.dtd">
We would do:
XDocument xDoc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XDocumentType("AutoApplication", null, "http://www.clientsite.com/public/DTD/autoappV1-3-level2.dtd", null));
);
+1
source to share