InnerText  获取或设置节点及其所有子节点的串联值。 
 InnerXml  获取或设置仅代表该节点的子节点的标记。 
 OuterXml  获取表示此节点及其所有子节点的标记。 
 Value  获取或设置节点的值。 
这几个怎么区别呢?MSDN中只有定义,没有具体的例子说明。请用一个具体的例子帮助说明一下。

解决方案 »

  1.   

    InnerText  是最简单的文本表示形式。
    InnerXml  会把文本表示成Xml形式。这就有了一个转换的过程。
    对于叶节点,InnerText 与 Value 属性返回相同的内容。下面的示例比较 InnerText 和 InnerXml 属性。
    using System;
    using System.Xml;
    public class Test {  public static void Main() {
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<root>"+
                    "<elem>some text<child/>more text</elem>" +
                    "</root>");    XmlNode elem = doc.DocumentElement.FirstChild;    // Note that InnerText does not include the up.
        Console.WriteLine("Display the InnerText of the element...");
        Console.WriteLine( elem.InnerText );    // InnerXml includes the up of the element.
        Console.WriteLine("Display the InnerXml of the element...");
        Console.WriteLine(elem.InnerXml);    // Set InnerText to a string that includes up.  
        // The up is escaped.
        elem.InnerText = "Text containing <up/> will have char(<) and char(>) escaped.";
        Console.WriteLine( elem.OuterXml );    // Set InnerXml to a string that includes up.  
        // The up is not escaped.
        elem.InnerXml = "Text containing <up/>.";
        Console.WriteLine( elem.OuterXml );
      }

      

  2.   

    下面的示例比较来自 InnerXml 和 OuterXml 属性的输出。
    using System;
    using System.IO;
    using System.Xml;public class Sample {  public static void Main() {    XmlDocument doc = new XmlDocument();
        doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
                    "<title>Pride And Prejudice</title>" +
                    "</book>");    XmlNode root = doc.DocumentElement;    // OuterXml includes the up of current node.
        Console.WriteLine("Display the OuterXml property...");
        Console.WriteLine(root.OuterXml);
                
        // InnerXml does not include the up of the current node.
        // As a result, the attributes are not displayed.
        Console.WriteLine();
        Console.WriteLine("Display the InnerXml property...");
        Console.WriteLine(root.InnerXml);
               
      }
    }