如何以下文件类型添加到一个XML文件的开头如何将文件类型添加到一个新的XML文件在C#中
<!DOCTYPE smil PUBLIC "-//W3C//DTD SMIL 2.0//EN" "http://www.w3.org/2001/SMIL20/SMIL20.dtd">
我想用C#XDocument
创建一个XML文件,但无法弄清楚如何将上述添加到XML文件
如何以下文件类型添加到一个XML文件的开头如何将文件类型添加到一个新的XML文件在C#中
<!DOCTYPE smil PUBLIC "-//W3C//DTD SMIL 2.0//EN" "http://www.w3.org/2001/SMIL20/SMIL20.dtd">
我想用C#XDocument
创建一个XML文件,但无法弄清楚如何将上述添加到XML文件
的开头你需要一个XDocumentType
添加到XDocument
的开头:
var xDocument = new XDocument(
new XDocumentType(
"smil",
"-//W3C//DTD SMIL 2.0//EN",
"http://www.w3.org/2001/SMIL20/SMIL20.dtd",
null
),
new XElement("Root")
);
有你试过XmlDocument.CreateDocumentType()
? MSDN link
试试这个 http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.createdocumenttype.aspx
//创建的XmlDocument。 XmlDocument doc = new XmlDocument();
//Create a document type node and
//add it to the document.
XmlDocumentType doctype;
doctype = doc.CreateDocumentType("book", null, null, "<!ELEMENT book ANY>");
doc.AppendChild(doctype);
//Create the root element and
//add it to the document.
doc.AppendChild(doc.CreateElement("book"));
你如何接受在stackoverflow中的答案。我不断收到有关不接受答案的警告。 – user1204195 2012-03-27 02:59:24
@ user1204195:单击数字下方左侧的空白复选标记。 – BoltClock 2012-03-27 03:02:14
@ user1204195:您点击投票计数器下方答案左侧的复选标记。 – 2012-03-27 03:02:48