Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在C中向新的XML文件添加文档类型#_C#_Xml_Doctype - Fatal编程技术网

C# 如何在C中向新的XML文件添加文档类型#

C# 如何在C中向新的XML文件添加文档类型#,c#,xml,doctype,C#,Xml,Doctype,如何将以下文档类型添加到XML文件的开头 <!DOCTYPE smil PUBLIC "-//W3C//DTD SMIL 2.0//EN" "http://www.w3.org/2001/SMIL20/SMIL20.dtd"> 我正在尝试使用C#XDocument创建一个XML文件,但不知道如何将上述内容添加到XML文件的开头您需要在XDocument的开头添加一个: var xDocument = new XDocument( new XDocumentType(

如何将以下文档类型添加到XML文件的开头

<!DOCTYPE smil PUBLIC "-//W3C//DTD SMIL 2.0//EN" "http://www.w3.org/2001/SMIL20/SMIL20.dtd">

我正在尝试使用C#
XDocument
创建一个XML文件,但不知道如何将上述内容添加到XML文件的开头

您需要在
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")
);
您需要在
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()

您是否尝试过
XmlDocument.CreateDocumentType()
? 试试这个

//创建XmlDocument。 XmlDocument doc=新的XmlDocument()

//创建文档类型节点并
//将其添加到文档中。
XmlDocumentType doctype;
doctype=doc.CreateDocumentType(“book”,null,null,”);
doc.AppendChild(doctype);
//创建根元素并
//将其添加到文档中。
doc.AppendChild(doc.CreateElement(“book”);
试试这个

//创建XmlDocument。 XmlDocument doc=新的XmlDocument()

//创建文档类型节点并
//将其添加到文档中。
XmlDocumentType doctype;
doctype=doc.CreateDocumentType(“book”,null,null,”);
doc.AppendChild(doctype);
//创建根元素并
//将其添加到文档中。
doc.AppendChild(doc.CreateElement(“book”);

您如何在stackoverflow中接受答案。我一直收到关于不接受答案的警告。@user1204195:您单击数字下方左侧的空心复选标记。@user1204195:您单击投票计数器下方答案左侧的复选标记。@user1204195:现在,我不是在寻找选票,但如果您喜欢答案(或问题)您可以单击左侧的向上箭头。同样,如果你不喜欢某样东西,你可以单击向下箭头(也许还可以添加一条解释原因的注释)。也许你应该阅读FAQ:如何在stackoverflow中接受答案。我一直收到关于不接受答案的警告。@user1204195:您单击数字下方左侧的空心复选标记。@user1204195:您单击投票计数器下方答案左侧的复选标记。@user1204195:现在,我不是在寻找选票,但如果您喜欢答案(或问题)您可以单击左侧的向上箭头。同样,如果你不喜欢某样东西,你可以单击向下箭头(也许还可以添加一条解释原因的注释)。或许您应该阅读常见问题解答: