zoukankan      html  css  js  c++  java
  • [c# 20问] 2.如何转换XML文件

    添加System.Xml引用

    使用XmlReader转换字符串

    DEMO
            #region Parse Xml
            private static void ParseXml(string xmlString)
            {
                StringBuilder output = new StringBuilder();
                using(XmlReader reader= XmlReader.Create(new StringReader(xmlString)))
                {
                    reader.ReadToFollowing("book");
                    reader.MoveToFirstAttribute();
                    output.AppendLine("The genre value:"+reader.Value);
                    reader.ReadToFollowing("title");
                    output.AppendLine("Conten of the title element:"+reader.ReadElementContentAsString());
    
                }
                Console.WriteLine(output);
            }
            #endregion
            static void Main(string[] args)
            {
                #region Parse Xml
                String xmlString =
                    @"<bookstore>
                         <book genre='autobiography' pubicationdate='1981-3-22' ISBN='1-861003-11-0'>
                             <title>The Autobiograph of Benamin Franklin</title>
                             <author>
                                 <first-name>Benjamin</first-name>
                                 <last-name>Franklin</last-name>
                             </author>
                             <price>8.99</price>
                         </book>
                      </bookstore>";
                ParseXml(xmlString);
                Console.ReadLine();
                #endregion
            }
  • 相关阅读:
    使用phpize安装php模块
    centos如何卸载软件
    修改centos环境变量
    linux系统安装php扩展
    php单入口session处理
    session阻塞机制,解决方法
    uploadify插件的使用
    php图片上传代码
    validate插件的使用
    datepicker使用
  • 原文地址:https://www.cnblogs.com/yanyan45/p/3888527.html
Copyright © 2011-2022 走看看