首页 > 其他 > 详细

简单xml示例

时间:2016-06-14 10:14:48      阅读:171      评论:0      收藏:0      [点我收藏+]
技术分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string dataxml = @"
<Products>
<Product>
<ProductID>1</ProductID>
<ProductName>LINQ to XML</ProductName>
<UnitPrice>10</UnitPrice>
</Product>
<Product>
<ProductID>2</ProductID>
<ProductName>LINQ to SQL</ProductName>
<UnitPrice>20</UnitPrice>
</Product>
</Products>";
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(dataxml);
            XmlElement root=doc.DocumentElement;
            XmlNodeList objxml = root.SelectNodes("/Products/Product");
            foreach (XmlNode e in objxml)
            {
                Console.WriteLine("{0}-{1}-{2}", e.SelectSingleNode("ProductID").InnerText, e.SelectSingleNode("ProductName").InnerText, e.SelectSingleNode("UnitPrice").InnerText);               
            }
            Console.ReadLine();
        }
    }
}
View Code

 

简单xml示例

原文:http://www.cnblogs.com/myloveblogs/p/5582953.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!