zoukankan      html  css  js  c++  java
  • 使用XmlTextWriter和XmlTextReader操作Xml文件

    具体用法参考如下代码

    XmlTextWriter:

    XmlTextWriter writer = new XmlTextWriter(strmMetadata, Encoding.UTF8) {
    Formatting = Formatting.Indented
    };
    writer.WriteStartDocument();
    writer.WriteStartElement("Session");
    writer.WriteAttributeString("SID", this.id.ToString());
    writer.WriteAttributeString("BitFlags", ((uint) this.BitFlags).ToString("x"));

    writer.WriteEndElement();
    writer.WriteEndDocument();
    writer.Flush();



    XmlTextReader:

    代码分析:
    XmlTextReader reader = new mlTextReader(strmMetadata);
    while (reader.Read())
    {
    string str3;
    if ((reader.NodeType == XmlNodeType.Element) && ((str3 = reader.Name) != null))
    {
    if (!(str3 == "Session"))
    {
    if (str3 == "SessionFlag")
    {
    goto Label_00BB;
    }
    if (str3 == "SessionTimers")
    {
    goto Label_00E1;
    }
    if (str3 == "PipeInfo")
    {
    goto Label_0292;
    }
    }
    else
    {
    }
    }
    continue;
    Label_00BB:
    this.oFlags.Add(reader.GetAttribute("N"), reader.GetAttribute("V"));
    continue;
    Label_00E1:
    this.Timers.ClientConnected = XmlConvert.ToDateTime(reader.GetAttribute("ClientConnected"), XmlDateTimeSerializationMode.RoundtripKind);
    string attribute = reader.GetAttribute("ClientBeginRequest");
    if (attribute != null)
    {
    this.Timers.ClientBeginRequest = XmlConvert.ToDateTime(attribute, XmlDateTimeSerializationMode.RoundtripKind);
    }
    reader.Close();



    1,使用while循环配合continue,goto语句来读取节点信息。

    2,使用GetAttribute函数时,结果!=null的判断。

  • 相关阅读:
    canvas
    canvas基础
    canvas基础
    面向对象
    函数的原型链
    原型链&Object的一些方法
    普通函数和构造函数
    下载RDO OpenStack RPM
    RHEL7修改swappiness
    2016年新年愿望
  • 原文地址:https://www.cnblogs.com/yczz/p/2280428.html
Copyright © 2011-2022 走看看