小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

xmlnode 的value與innertext區(qū)別

 隱形的翅膀 2008-02-28
1。當node是葉子節(jié)點時
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<right>a</right>");
        XmlNode root = doc.DocumentElement;
        Console.WriteLine(root.InnerText);
結(jié)果是:a
 
2。當node是父節(jié)點時,將包括子節(jié)點的所有的innertext顯示出來
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<root name=‘jack‘ value = ‘jacky‘ ><right>a</right><left>b</left>content</root>");
        XmlNode root = doc.DocumentElement;
        Console.WriteLine(root.InnerText);
結(jié)果是:abcontent
 
3。顯示屬性值
   如果想顯示root的name屬性值,可以通過innertext和value獲得
         XmlDocument doc = new XmlDocument();
        doc.LoadXml("<root name=‘jack‘ value = ‘jacky‘ ><right id =‘007‘>a</right><left>b</left>content</root>");
        XmlNode root = doc.DocumentElement;
        XmlNode node = root.SelectSingleNode("right");
        Console.WriteLine(node.Attributes["id"].InnerText);
        Console.WriteLine(node.Attributes["id"].Value);
 
或者 XmlNode root = doc.DocumentElement;
        XmlNode node = root.SelectSingleNode("right");
         node = node.SelectSingleNode("@id");

        Console.WriteLine(node.InnerText);
        Console.WriteLine(node.Value);
 
4。當取節(jié)點的Value時,我們發(fā)現(xiàn)為空

        XmlNode root = doc.DocumentElement;
        XmlNode node = root.SelectSingleNode("right");
        Console.WriteLine(node.Value);//rerult is  null reference
        Console.WriteLine(node.InnerText);// result is a

 原因是:
value這個屬性比較特殊,它返回的值與當前節(jié)點的nodetype有關(guān):(MSDN)

Type

Value

Attribute

The value of the attribute.

CDATASection

The content of the CDATA Section.

Comment

The content of the comment.

Document

a null reference (Nothing in Visual Basic).

DocumentFragment

a null reference (Nothing in Visual Basic).

DocumentType

a null reference (Nothing in Visual Basic).

Element

a null reference (Nothing in Visual Basic). You can use the XmlElement.InnerText or XmlElement.InnerXml properties to access the value of the element node.

Entity

a null reference (Nothing in Visual Basic).

EntityReference

a null reference (Nothing in Visual Basic).

Notation

a null reference (Nothing in Visual Basic).

ProcessingInstruction

The entire content excluding the target.

Text

The content of the text node.

 
例4中node的nodetype是element,所以通過value返回值是空引用,而當我們?nèi)〉脤傩缘膙alue時,因為它的nodetype為attribute,他返回是屬性的值

 

 
 
 

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多