zoukankan      html  css  js  c++  java
  • C#读写xml文件. 2

    此文来源:http://kb.cnblogs.com/page/42226/?page=2
    3、删除 <book genre="fantasy" ISBN="2-3631-4">节点的genre属性,删除 <book genre="update李赞红" ISBN="2-3631-4">节点。

    Code
    最后结果为:
    Code
    <?xml version="1.0" encoding="gb2312"?>
    <bookstore>
    <book ISBN="2-3631-4">
    <title>Oberon's Legacy</title>
    <author>Corets, Eva</author>
    <price>5.95</price>
    </book>
    <book>
    </book>
    </bookstore>
    4、显示所有数据。

    XmlNode xn=xmlDoc.SelectSingleNode("bookstore");
    XmlNodeList xnl
    =xn.ChildNodes;

    foreach(XmlNode xnf in xnl)
    {
    XmlElement xe
    =(XmlElement)xnf;
    Console.WriteLine(xe.GetAttribute(
    "genre"));//显示属性值
    Console.WriteLine(xe.GetAttribute("ISBN"));

    XmlNodeList xnf1
    =xe.ChildNodes;
    foreach(XmlNode xn2 in xnf1)
    {
    Console.WriteLine(xn2.InnerText);
    //显示子节点点文本
    }
    }
  • 相关阅读:
    5月27日
    5月26日
    5月25日
    5月24日
    5月22日
    梦断代码(3)
    01团队冲刺
    07周总结
    06周总结
    构建之法阅读笔记
  • 原文地址:https://www.cnblogs.com/xvqm00/p/1534928.html
Copyright © 2011-2022 走看看