zoukankan      html  css  js  c++  java
  • Use XML in Windows Phone 8.0

    I have an XML file stored in DataModel folder, the structure is shown as below:

    <?xml version="1.0" encoding="utf-8" ?>
    <Bible>
      <Setting>
        <a>1</a>
        <b>2</b>
        <c>3</c>
      </Setting>
      <books>
        <book id="a">
          <display>aaaaaaaa</display>
        </book>
      </books>
    </Bible>

    In windows phone 8.0, there is a way to use Dom:

    using Windows.Storage;
    using Windows.Data.Xml.Dom;
            public async void ManipulateXML()
            {
                string file = @"ms-appx:///DataModel/Data.xml";
                Uri url = new Uri(file);
                StorageFile sFile = await StorageFile.GetFileFromApplicationUriAsync(url);
    
                string stream = await FileIO.ReadTextAsync(sFile);
                XmlDocument xDoc = new XmlDocument();
                xDoc.LoadXml(stream);
    
                // append node
                var node = xDoc.SelectSingleNode("/Bible/Setting");
                XmlElement ele1 = xDoc.CreateElement("program");
                ele1.InnerText = "this is created by program";
                ele1.SetAttribute("ID", "Third");
                node.AppendChild(ele1);
                await xDoc.SaveToFileAsync(sFile);
    
                // remove node
                var settings = xDoc.SelectSingleNode("/Bible/Setting");
                var nodes = xDoc.SelectNodes("/Bible/Setting/program");
                int count = nodes.Count;
                for (int i = 0; i < count; i++)
                {
                    settings.RemoveChild(nodes[i]);
                    await xDoc.SaveToFileAsync(sFile);
                }
            }
  • 相关阅读:
    Codeforces 691A Fashion in Berland
    HDU 5741 Helter Skelter
    HDU 5735 Born Slippy
    HDU 5739 Fantasia
    HDU 5738 Eureka
    HDU 5734 Acperience
    HDU 5742 It's All In The Mind
    POJ Euro Efficiency 1252
    AtCoder Beginner Contest 067 C
    AtCoder Beginner Contest 067 D
  • 原文地址:https://www.cnblogs.com/qixue/p/4118878.html
Copyright © 2011-2022 走看看