zoukankan      html  css  js  c++  java
  • Windows 8学习笔记(二)——XML文件的操作

    今天用了一下Win8 Metro中XML文件的操作,发现在很有必须整理下来,虽然用法很简单,但每次用的时候都有些不顺手。

            读取XML文件

               Windows.Storage.StorageFolder storageFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync (Folder);
               Windows.Storage.StorageFile storageFile = await  storageFolder.GetFileAsync(file);
               Windows.Data.Xml.Dom.XmlLoadSettings xmlloadsettings = new XmlLoadSettings();
               xmlloadsettings.ProhibitDtd = false;
               xmlloadsettings.ResolveExternals = false;
               xmlloadsettings.ElementContentWhiteSpace = true;
               XmlDocument doc = await Windows.Data.Xml.Dom.XmlDocument.LoadFromFileAsync(storageFile, xmlloadsettings);

               string xmlData = doc.GetXml();

               显示如下:

                      image

               增加节点

               //增加节点
               var nodelist = doc.SelectNodes("/rss/channel");
               for (int i = 0; i < 3; i++)
               {
                   XmlElement ele1 = doc.CreateElement("ChannelType");
                   XmlElement e1 = doc.CreateElement("ChannelID");
                   e1.InnerText = "NO" + i.ToString();
                   ele1.AppendChild(e1);
                   XmlElement e2 = doc.CreateElement("ChannelName");
                   e2.InnerText = "Channel" + i.ToString();
                   ele1.AppendChild(e2);

                   nodelist[0].AppendChild(ele1);
               }

               await doc.SaveToFileAsync(storageFile);

              结果如下:

               aa

               查询并修改相应的节点

               var node = nodelist[0].SelectNodes("ChannelType");
               node[0].SelectSingleNode("ChannelID").InnerText = "channel12";

               await doc.SaveToFileAsync(storageFile);

               结果如下:

                 aa

     

               删除节点

               var nodeMain = nodelist[0].SelectNodes("ChannelType")[0];
               var noderemove = nodeMain.SelectSingleNode("ChannelID");
               nodeMain.RemoveChild(noderemove);

               await doc.SaveToFileAsync(storageFile);

               结果显示:

                 aa
     

               以上就是XML的简单操作,排版很别扭,下了两个代码插件却安装不上,很是纠结,先将就一下了,我再找找看有没好的代码插件,人家的代码排版很美,而我的呼呼~~哭泣的脸

    Trackback:http://www.cnblogs.com/jing870812/archive/2012/03/30/2426119.html

  • 相关阅读:
    Oracle笔记(三) Scott用户的表结构
    Oracle笔记(一) Oracle简介及安装
    Oracle笔记(七) 数据更新、事务处理、数据伪列
    Oracle笔记(六) 多表查询
    Oracle笔记(九) 表的创建及管理
    Oracle笔记(四) 简单查询、限定查询、数据的排序
    CentOS 6.3下部署LVS(NAT)+keepalived实现高性能高可用负载均衡
    PostgreSQL学习手册(十七) PL/pgSQL过程语言
    Oracle笔记(八) 复杂查询及总结
    Oracle笔记(十二) 集合、序列
  • 原文地址:https://www.cnblogs.com/hdjjun/p/2574936.html
Copyright © 2011-2022 走看看