C#»ñÈ¡XMLÎļþÖ¸¶¨½ÚµãµÄÊý¾Ý
ʵÀý˵Ã÷»á¸üÇå³þЩ£¬¼ÙÉèÓÐÈçÏÂXMLÎļþ£º
¡¡File: message_hutaow.xml
<?xml version="1.0" encoding="UTF-8"?>
<hutaow:Message version="1.0" xmlns:hutaow="http://wangtao.cublog.cn">
<hutaow:Head>
<hutaow:Date>20080502</hutaow:Date>
<hutaow:Source>
<hutaow:Address>192.168.0.1</hutaow:Address>
<hutaow:name>HUTAOW_HOST</hutaow:name>
</hutaow:Source>
<hutaow:Target>
<hutaow:Address>192.168.0.19</hutaow:Address>
</hutaow:Target>
</hutaow:Head>
</hutaow:Message>
¡¡¡¡ÏÖÔÚÒª¶ÁÈ¡ÏûÏ¢Ô´(Source)¼°Ä¿µÄ(Target)µÄIPµØÖ·(Address)¡£
¡¡¡¡Ò²¾ÍÊÇÐèÒª»ñÈ¡"/Message/Head/Source/Address"¼°"/Message/Head/Target/Address"µÄÊý¾Ý£¬ÐèÒªÓõ½XPathµÄÑ°¾¶·½Ê½£¬¾ßÌå´úÂëÈçÏ£º
//ÐèÒªÒýÓÃSystem.Xml¿â
using System.Xml;
/*
* Ê¡ÂÔÖмäÎ޹شúÂë
*/
//¼ÓÔØXMLÎļþ
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("message_hutaow.xml");
//XMLÎļþÖÐʹÓÃÁËÃüÃû¿Õ¼ä
XmlNamespaceManager xmlNamespace = new XmlNamespaceManager(xmlDoc.NameTable);
xmlNamespace.AddNamespace("hutaow", "http://wangtao.cublog.cn");
//ʹÓÃXPath·½Ê½Ñ°ÕÒÔ´IPµØÖ·½Úµã²¢Êä³ö
xmlNode = xmlDoc.SelectSingleNode("/hutaow:Message/hutaow:Head/hutaow:Source/hutaow:Address", xmlNamespace);
Console.WriteLine("Source Address: {0}",xmlNode.InnerText);
//ʹÓÃXPath·½Ê½Ñ°ÕÒÄ¿µÄIPµØÖ·½Úµã²¢Êä³ö
xmlNode = xmlDoc.SelectSingleNode("/hutaow:Message/hutaow:Head/hutaow:Target/hutaow:Address", xmlNamespace);
Console.WriteLine("Target Address: {0}",xmlNode.InnerText);
/*
* ¿ØÖÆ̨Êä³ö£º
* Source Address: 192.168.0.1
* Target Address: 192.168.0.19
*/
¡¡
Ïà¹ØÎĵµ£º
ºÜ¶àÈ˶ÔXpath¿ÉÄܱȽÏÊìϤ£¬µ«²»ÖªµÀÓÐûÓÐÖ±½Ó²Ù×÷¹ýÊý¾Ý¿â£¬ÎÒÃǶ¼ÖªµÀ ÔÚSql2005À﹫֧³ÖµÄ¼¸ÖÖ²éѯÓÐRaw£¬Auto£¬PathģʽµÈ£¬Èç¹ûÔÚ2000ÀïʹÓùý PathģʽµÄÅóÓÑÓ¦¸ÃÖªµÀ£¬ÊDz»ÈÝÒ×´¦Àí²éѯ½á¹ûµÄ£¬ÄÇôÔÚ2005Àï¶ÔÕâÒ»¿é×öÁ˺ܺõÄÌáÉý
ÎÒÏÈÀ´½éÉÜÒ»ÏÂʲôÊÇSql¡¡F ......
ÔÚ SQLServer2005 ÖÐ¶Ô XML µÄ´¦Àí¹¦ÄÜÏÔÈ»ÔöÇ¿Á˺ܶ࣬ÌṩÁË query(),value(),exist(),modify(),nodes() µÈº¯Êý¡£
¹ØÓÚ xml £¬ÄÑÒÔÀí½âµÄ²»ÊÇ SQLServer ÌṩµÄº¯Êý£¬¶øÊÇ¶Ô xml ±¾ÉíµÄÀí½â£¬¿´Ëƺܼòµ¥µÄÎļþ¸ñʽ£¬´¦ÀíÆðÀ´È´ÊǷdz£À§Äѵġ£±¾ÎÄÖ»ÊdzõÌ ......
¿ª·¢¹ýAndroidÓ¦ÓõÄͬѧÃǶ¼ÖªµÀ£¬Android¹¤³Ì-res-layout×ÊÔ´Îļþ¼ÐÏ´æ·Å×Å¿ØÖÆview²¼¾ÖµÄxmlÎļþ£¬ÎÒÃÇ¿ÉÒÔͬ¹ýgetViewById(int i)·½·¨£¬´ÓXMLÖй¹Ôìview¼°Æä×ÓÀ࣬ÔÚÕâ¸ö¹ý³Ìµ±ÖУ¬XMLÎļþÖеÄÒ»ÇÐlayoutÊôÐÔÒ²½«±»¸³ÓèÕâ¸öview¡£µ±È»£¬ÎÒÃÇÒ²Äܹ»Í¨¹ý´úÂëÀ´ÎªÄ³Ò»¸öviewÀ´ÉèÖÃlayout£¬ÄÇÊǺ󻰡£Í¨¹ý¶Ô¼ ......
Ò»¡¢²âÊÔÓõÄem.xml
<?xml version="1.0" encoding="GB2312"?>
<EW cmd="login" mod="Login" version="6.0">
<Source uns="" type="user"/>
<Username>zhangzhiyun@hp</Username>
<Password>111111</Password> ......
°üÀ¨Èý¸öÎļþ£ºstudentInfo.xml(´ý½âÎöµÄxmlÎļþ), Dom4jReadExmple.java(½âÎöµÄÖ÷ÒªÀà), TestDom4jReadExmple.java(²âÊÔ½âÎöµÄ½á¹û) £¨ÓÉÓÚʹÓÃcsdn blog×Ô´øµÄ´úÂëÕ³Ìù¹¤¾ß»á³¯Àï¼ÓÈëһЩ"..."×Ö·û£¬ËäÈ»ÀûÓڲ鿴£¬µ«ÊDz»ÀûÓÚ°Ñ´úÂëcopy³öÀ´ÔËÐУ¬¶øÇ××ÔÔËÐдúÂë¶Ô³ÌÐòÔ±À´ËµÊǺÜÖØÒªµÄ£¬¹ÊûÓÐʹÓÃcsdn blog×Ô´øµÄ´úÂëÕ³ ......