在XML中,带有问号的节点是什么,以及如何在C#中添加它们?

Ste*_*uer 14 c# xml

以下是在InfoPath中创建的XML文件的示例:

  <?xml version="1.0" encoding="UTF-8"?>
  <?mso-infoPathSolution solutionVersion="1.0.0.1" productVersion="12.0.0" PIVersion="1.0.0.0" href="file:///C:\Metastorm\Sample%20Procedures\InfoPath%20samples\Template1.xsn" name="urn:schemas-microsoft-com:office:infopath:Template1:-myXSD-2010-07-21T14-21-13" ?>
  <?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.2"?>
  <my:myFields xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-07-21T14:21:13" xml:lang="en-us">
    <my:field1>hello</my:field1>
    <my:field2>world</my:field2>
  </my:myFields>
Run Code Online (Sandbox Code Playgroud)

那些带有问号的前3个节点是什么叫...以及如何在C#中创建它们?

到目前为止我有这个:

  XmlDocument xmldoc;
  XmlDeclaration xmlDeclaration;

  xmldoc=new XmlDocument();
  xmlDeclaration = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, "", "") as XmlDeclaration;
  xmlDeclaration.Encoding = "UTF-8";
  xmldoc.AppendChild(xmlDeclaration);
Run Code Online (Sandbox Code Playgroud)

这适用于顶级XML声明节点,但如何创建接下来的两个?

提前致谢 :)

Pet*_*old 8

这些被称为处理指令.使用XmlDocument.CreateProcessingInstruction添加它们.

  • 请注意,第一个不是处理指令.这是XML文档声明.使用[CreateXmlDeclaration](http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.createxmldeclaration.aspx). (3认同)

Bry*_*ard 7

这些被称为处理指令.您可以使用XmlProcessingInstruction该类与它们进行交互XmlDocument.

与a中定义的大多数元素一样XmlDocument,您无法直接实例化它; 你必须使用适当的工厂方法XmlDocument(CreateProcessingInstruction在那种特殊情况下.)