• create XML


    string line1 = "44";
    string fas01 = "4";
    string jj1 = "1路车发案4起,3月1日1起";

    string line2 = "43";
    string fas02 = "6";
    string jj2 = "6路车发案4起,3月1日1起";

    XmlDocument doc = new XmlDocument();
    //创建XML声明部分
    XmlDeclaration Declaration = doc.CreateXmlDeclaration("1.0", "utf-8", null);
    doc.InsertBefore(Declaration, doc.DocumentElement);
    //创建根节点
    XmlElement Root = doc.CreateElement("Root");//主内容
    doc.AppendChild(Root);


    XmlElement Child1 = doc.CreateElement("luduan");

    XmlAttribute attr1 = doc.CreateAttribute("mingcheng");
    attr1.Value = line1;
    Child1.Attributes.Append(attr1);

    XmlElement fas1 = doc.CreateElement("fas");
    fas1.InnerText = fas01;
    Child1.AppendChild(fas1);

    XmlElement jianjie = doc.CreateElement("jianjie");
    jianjie.InnerText = jj1;
    Child1.AppendChild(jianjie);

    Root.AppendChild(Child1);

    Child1 = doc.CreateElement("luduan");
    attr1 = doc.CreateAttribute("mingcheng");
    attr1.Value = line2;
    Child1.Attributes.Append(attr1);

    fas1 = doc.CreateElement("fas");
    fas1.InnerText = fas02;
    Child1.AppendChild(fas1);

    jianjie = doc.CreateElement("jianjie");
    jianjie.InnerText = jj2;
    Child1.AppendChild(jianjie);

    Root.AppendChild(Child1);


    string path = Server.MapPath("~");
    string fullpath = path + "\Save\" + "1.xml";
    doc.Save(fullpath);


    string xmlFileName = Server.MapPath("Save/1.xml");

    //
    StreamReader sr = new StreamReader(xmlFileName, System.Text.Encoding.Default);

    string xmlData = sr.ReadToEnd();

    XmlDocument doc2 = new XmlDocument();
    doc2.LoadXml(xmlData);
    //
    doc2.Save("C://2.XML");

  • 相关阅读:
    简约 高效 基层管理体制
    六大纪律
    平行文
    党章
    四大考验 四大危险
    创新、协调、绿色、开放、共享五大发展理念
    微信公众号-->微信html页面缓存问题
    本地kafka环境部署
    >>读懂一本书:樊登读书法>>-->摘抄
    海龟交易法则(第3版)-->摘抄
  • 原文地址:https://www.cnblogs.com/gongyu/p/3992642.html
Copyright © 2020-2023  润新知