C#ÐÞ¸ÄXMLµÄ¼òµ¥Àý×Ó
½ÓÉÏһƪ¡¶C#дXMLµÄ¼òµ¥Àý×Ó¡·
Õâ¸öÀý×ÓÒªÐÞ¸ÄXMLÎļþÖнáµãµÄÊôÐԺͺÍÔªËصÄÎı¾
1 ÔxmlÎļþ bookstore.xml
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="love" ISBN="1234123">
<title>who am i </title>
<author>who</author>
<price>999</price>
</book>
<book leixing="music" ISBN="56756">
<title>CS´ÓÈëÃŵ½¾«Í¨</title>
<author>ºò½Ý</author>
<price>222</price>
</book>
</bookstore>
2 program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
//ʵÀý»¯Ò»¸öXmlDocument¶ÔÏó
XmlDocument xmlDoc = new XmlDocument();
//ʵÀý¶ÔÏó¶ÁȡҪдÈëµÄXMLÎļþ
xmlDoc.Load("bookstore.xml");
//»ñÈ¡bookstore½ÚµãµÄËùÓÐ×Ó½Úµã
XmlNodeList nodeList = xmlDoc.SelectSingleNode("bookstore").ChildNodes;
//±éÀúËùÓÐ×Ó½Úµã
foreach (XmlNode xn in nodeList)
{
//½«×Ó½ÚµãÀàÐÍ
Ïà¹ØÎĵµ£º
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Syste ......
xmlÎļþÈçÏ£º<?xml version="1.0" encoding="gb2312"?>
<Èí¼þ¹ÜÀíϵͳ>
<¹ÜÀíÔ±>
<Óû§Ãû>Ã÷ÈտƼ¼</Óû§Ãû>
<ÃÜÂë>123456</ÃÜÂë>
<µØÖ·>³¤´ºÊÐ</µØÖ·>
</¹ÜÀíÔ±>
<¹ÜÀíÔ±>
<Óû§Ãû>Ã÷ÈÕÈí¼þ</Óû§Ãû ......
Ò»£ºÉè¼Æģʽ²¿·Ö
״̬ģʽ£¨state£©
״̬ģʽÀàËÆÓÚÒ»ÖÖ¼òµ¥µÄ¹¤×÷Á÷£¬ÓÃÀ´°Ñ´óÁ¿µÄÅжϷÖÖ§½øÐвð·Ö£¬¸øÿһÖÖÅжÏÔö¼ÓÒ»¸ö״̬£¬Èç¹û²»Âú×ã¸ÃÅжϿÉÒÔ½øÐÐ״̬ת»»£¬ÖªµÀÓöµ½Âú×ãÌõ¼þΪֹ
ÕâÑù×öµÄºÃ´¦¾ÍÊÇ£¬µ±ÐèÒªÔö¼ÓÅжϵÄʱºò£¬²»ÐèÒª¸Ä±äÒѾ´æÔڵĴúÂë¡£Ö»ÐèÒªÔö¼ÓÅжϵÄÀ࣬ÔʼÅжÏÀàÖÐÔö¼ÓеÄ״̬ת»»¡£
Ê ......
Õâ¸öÀý×ÓÒª°Ñbookstore.xmlÎļþÔö¼ÓÒ»Ìõbook¼Ç¼
1 bookstore.xml
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="love" ISBN="1234123">
<title>who am i </title>
<author>who</author>
  ......