zoukankan      html  css  js  c++  java
  • xml .net 用法

    1.using System.Xml;
    2.//初始化一个xml实例
    3.XmlDocument xml=new XmlDocument();
    4.//导入指定xml文件
    5.xml.Load(path);
    6.xml.Load(HttpContext.Current.Server.MapPath("~/file/bookstore.xml"));
    7.//指定一个节点
    8.XmlNode root=xml.SelectSingleNode("/root");
    9.//获取节点下所有直接子节点
    10.XmlNodeList childlist=root.ChildNodes;
    11.//判断该节点下是否有子节点
    12.root.HasChildNodes;
    13.//获取同名同级节点集合
    14.XmlNodeList nodelist=xml.SelectNodes("/Root/News");
    15.//生成一个新节点
    16.XmlElement node=xml.CreateElement("News");
    17.//将节点加到指定节点下,作为其子节点
    18.root.AppendChild(node);
    19.//将节点加到指定节点下某个子节点前
    20.root.InsertBefore(node,root.ChildeNodes[i]);
    21.//为指定节点的新建属性并赋值
    22.node.SetAttribute("id","11111");
    23.//为指定节点添加子节点
    24.root.AppendChild(node);
    25.//获取指定节点的指定属性值
    26.string id=node.Attributes["id"].Value;
    27.//获取指定节点中的文本
    28.string content=node.InnerText;
    29.//保存XML文件
    30.string path=Server.MapPath("~/file/bookstore.xml");
    31.xml.Save(path);
    32.//or use :xml.Save(HttpContext.Current.Server.MapPath("~/file/bookstore.xml"));

  • 相关阅读:
    新的思考方式
    我在干售后!
    设计制造嵌入式系统
    镶嵌在系统中的系统
    苏黄永郦的第六周读书报告
    苏黄永郦的第五周读书报告
    苏黄永郦的第四周读书报告
    苏黄永郦的第三周读书报告
    1051 最大子矩阵和
    1065 最小正子段和
  • 原文地址:https://www.cnblogs.com/haihang/p/2800835.html
Copyright © 2011-2022 走看看