zoukankan      html  css  js  c++  java
  • XmlReader读取XML

    StringBuilder output = new StringBuilder();
    
    String xmlString =
        @"<bookstore>
        <book genre='autobiography' publicationdate='1981-03-22' ISBN='1-861003-11-0'>
            <title>The Autobiography of Benjamin Franklin</title>
            <author>
                <first-name>Benjamin</first-name>
                <last-name>Franklin</last-name>
            </author>
            <price>8.99</price>
        </book>
    </bookstore>";
    
    // Create an XmlReader
    using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
    {
        reader.ReadToFollowing("book");
    
        if (reader.HasAttributes)
        {
            output.Append("Attributes of <" + reader.Name + ">");
            for (int i = 0; i < reader.AttributeCount; i++)
            {
                reader.MoveToAttribute(i);
                output.Append(" " + reader.Name + "=" + reader.Value);
            }
            reader.MoveToElement(); // Moves the reader back to the element node.
        }
    
    }
    
    OutputTextBlock.Text = output.ToString();
    

      

  • 相关阅读:
    spring整合myBatis
    spring之事物
    spring之AspectJ实现AOP
    AOP之JDK动态代理和CGLib动态代理
    iOS-面试相关<一>
    iOS -调试工具Instruments使用总结
    iOS-阅读器常年崩溃问题记录
    iOS
    ios
    iOS
  • 原文地址:https://www.cnblogs.com/liqipeng/p/4576156.html
Copyright © 2011-2022 走看看