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);
    //显示子节点点文本
    }
    }
  • 相关阅读:
    for循环中break和continue的区别
    详解vue生命周期及每个阶段适合进行的操作
    ansible部署
    ansible介绍
    jenkins介绍和安装
    查看磁盘型号和内存及raid信息
    shell 概览
    day5 函数和参数
    day4(dict和set)
    day3(if和for)
  • 原文地址:https://www.cnblogs.com/xvqm00/p/1534928.html
Copyright © 2011-2022 走看看