tags:

views:

68

answers:

2

hi all,

I am trying to figure out of the CreateDocumentType() works in C# and although i have already found and read the msdn page on it, i can not get it to work for me.

I am simply trying to create this line in my xml document:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; 

Can someone help me out with the syntax required for this

EDIT: code so far, with htmldoc being an xmldocument declared further up in the code.

string dtdLink = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
string dtdDef = "-//W3C//DTD XHTML 1.0 Transitional//EN";

XmlDocumentType docType = htmlDoc.CreateDocumentType("html", "PUBLIC", dtdLink, dtdDef);
htmlDoc.AppendChild(docType);

This does NOT work.

A: 

try this

var dt = document.implementation.createDocumentType('svg:svg', '-//W3C//DTD SVG 1.1//EN', 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd');
var d = document.implementation.createDocument('http://www.w3.org/2000/svg', 'svg:svg', dt);
alert(d.doctype.publicId); // -//W3C//DTD SVG 1.1//EN

i have got it from this link https://developer.mozilla.org/En/DOM/DOMImplementation.createDocumentType

hope it will be useful for you.

Amit
A: 

Not sure what you've tried so far, but the existing sample in the method's msdn page (CreateDocumentType, then AppendChild to the doc) seems to work fine, just passing params of "html", "-//W3C//DTD XHTML 1.0 Transitional//EN", and "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" to get the doctype you mentioned

James Manning