zoukankan      html  css  js  c++  java
  • 在win8创建、读取、保存xaml文件

    一、创建xml文件:

                docElement = new XmlDocument();
                XmlProcessingInstruction pi = docElement.CreateProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
                docElement.AppendChild(pi);
                rootElement = docElement.CreateElement("s_sign_content");//创建根节点(一级)
                docElement.AppendChild(rootElement);


    二、读取xml文件:

    分为两种,一是从工程的文件夹下读取;二是从工程存放的文件位置读取

    从工程存放的文件位置读取:

     private async void IsolatedStorage()
            {
                var _name = "mydata.xml";
                var _Folder = Windows.Storage.ApplicationData.Current.LocalFolder;
                try
                {
                    var _File = await _Folder.GetFileAsync(_name);
                    XmlLoadSettings loadsettings = new XmlLoadSettings();
                    loadsettings.ProhibitDtd = false;
                    loadsettings.ResolveExternals = false;
                    XmlDocument xmlDocument = await XmlDocument.LoadFromFileAsync(_File, loadsettings);
                    //XmlNodeList nodelist = RootXmlDoc.GetElementsByTagName("curve");
                    XmlNodeList curveNodeList = xmlDocument.GetElementsByTagName("curve");
                    // reDrawPen(curveNodeList, 0);
                    XmlNodeList sealNodeList = xmlDocument.GetElementsByTagName("seal");
                }
                catch
                {
    
                }
                //reDrawStamp(sealNodeList);
            }

    从项目工程的文件夹下读取:

     private async void readXml()
            {
                string xml = @"Assets\mydata.xml";
                StorageFolder installationFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
                StorageFile storageFile = await installationFolder.GetFileAsync(xml);
                XmlLoadSettings loadsettings = new XmlLoadSettings();
                loadsettings.ProhibitDtd = false;
                loadsettings.ResolveExternals = false;
                XmlDocument xmlDocument = await XmlDocument.LoadFromFileAsync(storageFile, loadsettings);
                //XmlNodeList nodelist = RootXmlDoc.GetElementsByTagName("curve");
                XmlNodeList curveNodeList = xmlDocument.GetElementsByTagName("curve");
                reDrawPen(curveNodeList, 0);
                XmlNodeList sealNodeList = xmlDocument.GetElementsByTagName("seal");
                reDrawStamp(sealNodeList);
            }

    三、保存xml文件
        保存在工程文件存放的位置;

    private async void saveXml()
            {
                //保存在本地应用程序的根目录下
                StorageFolder sFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("UserInputData", CreationCollisionOption.OpenIfExists);
                StorageFile sFile = await sFolder.CreateFileAsync("mydata.xml", CreationCollisionOption.OpenIfExists);
                await docElement.SaveToFileAsync(sFile);
            }
    不积跬步,无以至千里!
  • 相关阅读:
    SQL高效运行注意事项(四)
    SQL Serve里DBA要去改变的3个配置选项
    sql还原数据库时候,遇到数据库被占用的解决情况
    sqlserver中将datetime类型转换为yyyyMMddHHmmss格式
    SQL 高效运行注意事项(三)
    当您解开后您从 Internet 上下载的压缩的文件时,文件的修改日期更改为您提取它的日期
    MySQL通过自定义函数实现递归查询父级ID或者子级ID
    YII2集成GOAOP,实现面向方面编程!
    C语言关于指针的注意事项
    转载 could not find a getter for ... in class ... 异常的原因解析
  • 原文地址:https://www.cnblogs.com/xiaolifeidao/p/2870976.html
Copyright © 2011-2022 走看看