C#ÖвÙ×÷XML Node½Úµãϸ½Ú²Ù×÷
ÓõÄÊÇÒ»Öֺܱ¿µÄ·½·¨£¬µ«¿ÉÒÔ°ïÖú³õѧÕßÁ˽â·ÃÎÊXML½ÚµãµÄ¹ý³Ì¡£
ÒÑÖªÓÐÒ»¸öXMLÎļþ£¨bookstore.xml£©ÈçÏÂ:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
</bookstore>
1¡¢Íù<bookstore>½ÚµãÖвåÈëÒ»¸ö<book>½Úµã£º
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load("bookstore.xml");
XmlNode root=xmlDoc.SelectSingleNode("bookstore");//²éÕÒ<bookstore>
XmlElement xe1=xmlDoc.CreateElement("book");//´´½¨Ò»¸ö<book>½Úµã
xe1.SetAttribute("genre","ÀîÔÞºì");//ÉèÖøýڵãgenreÊôÐÔ
xe1.SetAttribute("ISBN","2-3631-4");//ÉèÖøýڵãISBNÊôÐÔ
XmlElement xesub1=xmlDoc.CreateElement("title");
xesub1.InnerText="CS´ÓÈëÃŵ½¾«Í¨";//ÉèÖÃÎı¾½Úµã
xe1.AppendChild(xesub1);//Ìí¼Óµ½<book>½ÚµãÖÐ
XmlElement xesub2=xmlDoc.CreateElement("author");
xesub2.InnerText="ºò½Ý";
xe1.AppendChild(xesub2);
XmlElement xesub3=xmlDoc.CreateElement("price");
xesub3.InnerText="58.3";
xe1.AppendChild(xesub3);
root.AppendChild(xe1);//Ìí¼Óµ½<bookstore>½ÚµãÖÐ
xmlDoc.Save("bookstore.xml");
//================
½á¹ûΪ£º
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
<book genre="ÀîÔÞºì" ISBN="2-3631-4">
<title>CS´ÓÈëÃŵ½¾«Í¨</title>
&
Ïà¹ØÎĵµ£º
±¾ÎĽéÉÜÁ˸÷ÖÖ½âÎö·½·¨£¬×ÅÖØ·ÖÎöÁ˸÷×ÔµÄÓÅȱµã:
½âÎöµÄÖØÒªÐÔ
¡¡¡¡½âÎöΪʲôÖØÒª?ÒòΪËùÓÐ XML ´¦Àí¶¼´Ó½âÎö¿ªÊ¼¡£ÎÞÂÛʹÓø߲ã±à³ÌÓïÑÔ(Èç XSLT)»¹ÊǵͲã Java ±à³Ì£¬µÚÒ»²½¶¼ÊÇÒª¶ÁÈë XML Îļþ£¬½âÂë½á¹¹ºÍ¼ìË÷ÐÅÏ¢µÈµÈ£¬Õâ¾ÍÊǽâÎö¡£
¡¡¡¡½âÎöÎĵµÊ±ÃæÁٵĵÚÒ»¸öÑ¡ÔñÊDzÉÓÃÏֳɵĽâÎö¿â(»ù±¾ÉÏÿÖÖ±à³ÌÓïÑÔ¶¼Ó ......
²Î¿¼²©ÎÄ¡¶IEÏÂÀûÓÃjQuery·ÖÎöXML¡·µØÖ·£ºhttp://www.newmediafun.com/2009/07/parsing-xml-with-jquery-in-internet-explorer/
±¾À´ÒÔΪjQuery»áºÜºÃµÄ½â¾öËùÓÐä¯ÀÀÆ÷¼æÈÝÐÔÎÊÌ⣬µ«ÊÇÕóÍöµÄIE6»¹ÊÇ»áÕÒÂé·³£¡
jQueryʹÓÃAJAXʱ£¬ÔÚIE6϶ÁÈ¡»Ø´«µ½XMLÊý¾Ý»áÓÐÎÊÌ⣬¾ßÌå¿´ÏÂÃæµÄÀý×Ó°É¡£
×¼±¸Êý¾ÝÎļþtest.xml
<Ar ......
ËùÓÐ XML ÎĵµÖеÄÎı¾¾ù»á±»½âÎöÆ÷½âÎö¡£
Ö»ÓÐ CDATA Çø¶Î£¨CDATA section£©ÖеÄÎı¾»á±»½âÎöÆ÷ºöÂÔ¡£
Parsed Data
XML ½âÎöÆ÷ͨ³£»á½âÎö XML ÎĵµÖÐËùÓеÄÎı¾¡£
µ±Ä³¸ö XML ÔªËر»½âÎöʱ£¬Æä±êÇ©Ö®¼äµÄÎı¾Ò²»á±»½âÎö£º
<message>´ËÎı¾Ò²»á±»½âÎö</message>
½âÎöÆ÷Ö®ËùÒÔÕâô×öÊÇÒòΪ XML ÔªËØ¿É°ü ......
ÎÒÃdz£³£ÐèÒª¶ÁÈ¡xmlÎļþ£¬°ÑÀïÃæµÄÐÅϢת»¯ÎªÎÒÃÇ×Ô¶¨ÒåµÄÀàÐÍ£¬»òÔò°É×Ô¶¨ÒåÀàÐÍת»¯ÎªXml×Ö·û´®¡£ÔÚÕâÀï½éÉÜÒ»¸ö±È½Ï¼òµ¥µÄ¶ÔÏóת»¯·½·¨¡£ÔÚÎÒ×Ô¼ºµÄFramworkÀïÃæÒ²¶à´ÎÓõ½¡£ÀïÃæÉæ¼°µ½½Úµã¡¢ÊôÐÔ¡¢¼¯ºÏ¡£
ʾÀýÒ» ¸ÃxmlÎļþÉæ¼°µ½ÊôÐÔ¡¢½Úµã¼¯ºÏ²»Éæ¼°¸ö½Úµã£º
<?xml version="1.0" encoding="utf-8"?>
<da ......