zoukankan      html  css  js  c++  java
  • WP8_读写XML

    /// <summary>
        /// WP手机,XML读写类
        /// </summary>
        public class WPXmlRW
        {
            /// <summary>
            /// 向WP手机,写入xml文件
            /// </summary>
            /// <param name="argStreamReader"></param>
            /// <param name="argFileName">写入的文件名</param>
            public void WriteToXml(StreamReader argStreamReader, string argFileName = "abc.xml")
            {
                //StreamReader sr = new StreamReader(stream123);//转化为可读流
     
                using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    //解析流 转化为XML
                    XElement _xml = XElement.Parse(argStreamReader.ReadToEnd());
     
                XDocument doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), _xml);
     
                    //创建一个本地存储的文件流
                    IsolatedStorageFileStream location = new IsolatedStorageFileStream(argFileName ,
                            System.IO.FileMode.Create, storage);
     
                    //将本地存储文件流转化为可写流
                    System.IO.StreamWriter file = new System.IO.StreamWriter(location);
     
                    //将XML文件 保存到流file上 即已经写入到手机本地存储文件上
                    doc.Save(file);
     
                    file.Dispose();
                    location.Dispose();
                }
     
            }
     
            /// <summary>
            /// 从WP手机中,读xml文件
            /// </summary>
            /// <param name="argFileName"></param>
            /// <returns></returns>
            public XElement ReadFromXml(string argFileName = "abc.xml")
            {
                using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    XElement _xml;//定义Linq的XML元素
                    //打开本地存储文件
                    IsolatedStorageFileStream location = new IsolatedStorageFileStream(argFileName, FileMode.Open, storage);
                    //转化为可读流
                    System.IO.StreamReader file = new System.IO.StreamReader(location);
                    //解析流 转化为XML
                    _xml = XElement.Parse(file.ReadToEnd());
     
                    file.Dispose();
                    location.Dispose();
     
                    if (_xml.Name.LocalName != null)
                    {
                        return _xml;
                    }
                }
                return null;
            }
        }
  • 相关阅读:
    BZOJ BLO 1123 (割点)【双连通】
    P4291 [HAOI2008]排名系统
    P3165 [CQOI2014]排序机械臂
    P3224 [HNOI2012]永无乡
    P1169 [ZJOI2007]棋盘制作
    P2303 [SDOi2012]Longge的问题
    P2216 [HAOI2007]理想的正方形
    P2473 [SCOI2008]奖励关
    P2617 Dynamic Rankings
    P2518 [HAOI2010]计数
  • 原文地址:https://www.cnblogs.com/jx270/p/3852426.html
Copyright © 2011-2022 走看看