• 复习一下xml(c)


      简单介绍

    Using System.Xml;

    XMLDocument xml=new XmlDocument();xml.Load(path);//初始化一个实例

    xml.Load(HttpContext.Current.Server.MapPath("~/file/bookstire.xml"));//导入指定xml文件

    XmlNode root=xml.SelectSingleNode("/root");//指定一个节点

    XmlNodeList childlist=root=root.ChildNodes;//获取节点下所有直接子节点

    root.HasChildNodes;//获取该节点下是否有子节点

    XmlNodeList nodelist=xml.SelectNodes("/Root/News");//获取同名同级节点集合

    XmlElement node=xml.CreateElement("News");//生成一个新节点

    root.ApprendChiled(node);//将节点加到指定节点下,作为其子节点

    root.AppendChild(node);//为指定节点添加子节点

    root.InsertBefore(node,root.ChildeNodes[i]);将节点加到指定节点下某个子节点前

    node.SetAttribute("id","111111");//为指定节点新建属性并赋值

    string id=node.Attributes["id"].Value;//获取指定节点的指定属性值

    string content=node.InnerText;//获取指定节点中的文本

    string path =Server.MapPath("~/file/bookstore.xml");xml.Save(path);//保存xml文件

    或: xml.Sace(HttpContext.Current.Server.MapPath("~/file/bookstore.xml"));

  • 相关阅读:
    237. Delete Node in a Linked List
    430. Flatten a Multilevel Doubly Linked List
    707. Design Linked List
    83. Remove Duplicates from Sorted List
    160. Intersection of Two Linked Lists
    426. Convert Binary Search Tree to Sorted Doubly Linked List
    142. Linked List Cycle II
    类之间的关系
    初始化块
    明确类和对象
  • 原文地址:https://www.cnblogs.com/yunfeioliver/p/9265179.html
Copyright © 2020-2023  润新知