zoukankan      html  css  js  c++  java
  • 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");

  • 相关阅读:
    FlashInspector 【Firefox浏览器插件,flash分析工具】
    屌丝和木耳
    Flash剪贴板功能
    sql newid()随机函数
    SQL 视图
    向SQL Server 现有表中添加新列并添加描述.
    sql server 约束 查找
    创建与删除SQL约束或字段约束
    SQLServer
    利用排序规则特点计算汉字笔划和取得拼音首字母
  • 原文地址:https://www.cnblogs.com/gongyu/p/3992642.html
Copyright © 2011-2022 走看看