代码之家  ›  专栏  ›  技术社区  ›  Stephen Oberauer

在XML中,调用了哪些带有问号的节点,以及如何将它们添加到C中?

  •  14
  • Stephen Oberauer  · 技术社区  · 15 年前

    以下是在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>
    

    有问号的前三个节点是什么…我如何在C中创建它们?

    到目前为止,我有:

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

    这对于顶部的XML声明节点很好,但是如何创建下两个节点呢?

    事先谢谢:)

    3 回复  |  直到 15 年前
        1
  •  8
  •   Peter Lillevold Rene    15 年前

    这些被称为处理指令。添加EM XmlDocument.CreateProcessingInstruction .

        2
  •  7
  •   Bryan Menard    15 年前

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

    与在 XML文档 ,不能直接实例化它;必须在上使用适当的工厂方法 XML文档 ( CreateProcessingInstruction 在这种情况下。)

        3
  •  2
  •   Stephen Oberauer    15 年前

    感谢您解释这些是处理说明。按照建议使用CreateProcessingInstruction,解决方案如下:

      xmlPi = xmldoc.CreateProcessingInstruction("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\"");
      xmldoc.AppendChild(xmlPi);