XmlÖÐSelectSingleNode·½·¨ÖеÄxpathÓ÷¨
×î³£¼ûµÄXMLÊý¾ÝÀàÐÍÓУºElement, Attribute£¬Comment, Text.
Element, Ö¸ÐÎÈç<Name>Tom<Name>µÄ½Úµã¡£Ëü¿ÉÒÔ°üÀ¨£ºElement, Text, Comment, ProcessingInstruction, CDATA, and EntityReference.
Attribute, Ö¸ÔÚ<Employee >ÖеĴÖÌ岿·Ö¡£
Comment£¬Ö¸ÐÎÈ磺<!-- my comment --> µÄ½Úµã¡£
Text£¬Ö¸ÔÚ<Name>Tom<Name>µÄ´ÖÌ岿·Ö¡£
ÔÚXMLÖУ¬¿ÉÒÔÓÃXmlNode¶ÔÏóÀ´²ÎÕÕ¸÷ÖÖXMLÊý¾ÝÀàÐÍ¡£
2.1 ²éѯÒÑÖª¾ø¶Ô·¾¶µÄ½Úµã£¨¼¯£©
objNodeList = objDoc.SelectNodes(“Company/Department/Employees/Employee”)
»òÕß
objNodeobjNodeList = objNode.SelectNodes(“/Company/Department/Employees/Employee”)
ÒÔÉÏÁ½ÖÖ·½·¨¿É·µ»ØÒ»¸öNodeList¶ÔÏó£¬Èç¹ûÒª·µ»Øµ¥¸ö½Úµã¿ÉʹÓÃSelectSingleNode·½·¨£¬¸Ã·½·¨Èç¹û²éѯµ½Ò»¸ö»ò¶à¸ö½Úµã£¬·µ»ØµÚÒ»¸ö½Úµã£»Èç¹ûûÓвéѯµÄÈκνڵ㷵»Ø Nothing¡£ÀýÈ磺
objNodeobjNode = objNode.SelectSingleNode(“/Company/Department/Employees/Employee”)
If Not (objNode is Nothing) then
‘- Do process
End If
2.2 ²éѯÒÑÖªÏà¶Ô·¾¶µÄ½Úµã£¨¼¯£©
¿ÉʹÓÃÀàËÆÓÚÎļþ·¾¶µÄÏà¶Ô·¾¶µÄ·½Ê½À´²éѯXMLµÄÊý¾Ý
objNode = objDoc.SelectSingleNode(“Company/Department”)
objNodeobjNodeList = objNode.SelectNodes(“../Department)
objNodeobjNode = objNode.SelectNode(“Employees/Employee”)
2.3 ²éѯÒÑÖªÔªËØÃûµÄ½Úµã£¨¼¯£©
ÔÚʹÓò»¹æÔòµÄ²ã´ÎÎĵµÊ±£¬ÓÉÓÚ²»ÖªµÀÖмä²ã´ÎµÄÔªËØÃû£¬¿ÉÊ
Ïà¹ØÎĵµ£º
ºÍAndroid UI layoutÒ»Ñù£¬ÎÒÃÇÒ²¿ÉÒÔÔÚXMLÖж¨ÒåÓ¦ÓóÌÐòµÄ²Ëµ¥¡£Í¨¹ýÔڲ˵¥µÄonCreateOptionsMenu·½·¨ÖÐÅòÕͲ˵¥layout¡£ÕâÑù×ö»áʹÎÒÃǵijÌÐò´úÂë¼òµ¥¶àÁË£¬¶øÇÒ¾¡¿ÉÄܵĽ«¸ü¶àµÄ½çÃæÉè¼Æ²¿·Ö·Åµ½XML£¬±ãÓÚä¯ÀÀ¡£
1. ÔÚ¹¤³ÌµÄ/res/Îļþ¼ÐÏ´´½¨menuÎļþ¼Ð£¬ÓÃÀ´±£´æÄãΪӦÓóÌÐò¶¨ÒåµÄ²Ëµ¥XMLÎļþ¡£
Ôڲ˵¥XML ......
×î½üÔÚsina¿´nbaµÄÎÄ×ÖÖ±²¥µÄʱºò£¬¶ÔÍøÕ¾ÓÒϽǵÄÄÇÒ»¸öÁÄÌì´°¿Ú²úÉúÐËȤ£¬¾Í¾ö¶¨×Ô¼ºÒ²×öÒ»¸ö¡£
ÉÏÍø²é²é×ÊÁÏ£¬ÕâÑùµÄÁÄÌìÊÒÎ޷ǾÍÊÇÓû§ÊäÈëÊý¾Ý´«µ½·þÎñÆ÷±£´æ£¬È»ºóÓû§Ò³ÃæÔÙʵʱµØ´ÓÊý¾Ý¿âÈ¡³öÊý¾Ý£¬ÏÔʾÔÚÒ³ÃæÉÏ£¬¼´¿ÉÍê³ÉÒ»´ÎÁÄÌì²Ù×÷¡£
Ê×ÏÈÎÒ¶¨ÒåÁËÒ»¸öxmlÎļþ£¬ÓÃÓÚ±£´æÓû§ ......
Ê×ÏÈ£¬¼ÓÔØTXTʵÀý£º
´úÂ룺
ËäÈ»ÊǺܾɵÄÒ»Ì׽̳̣¬¿ÉÊǺÜʵÓã¬ËùÒÔÎÒ°ÑËü·ÅÔÚÕâ¡£
£¨×¢Ò⣺¿´´úÂëµÄʱºòÁôÒâһϽڵãµÄÓ÷¨£ºmyXML.childNodes[0].childNodes[0].childNodes[0]....xml½ÚµãµÄµØ·½¡££©
Ò»¡¢½¨Á¢XML¶ÔÏó£º
var myXML = new XML();
¶þ¡¢ÒýÓÃXMLÎļþ£º
myXML.load("data.xml");
Èý¡¢ºöÂÔ¿Õ¸ñ£º
my ......
from:
http://zhidao.baidu.com/question/67891842.html?si=1
ÏÂÃæµÄÒ»ÐоÍÊÇÔÚµÚ¶þ±¾ÊéµÄ¶¨Òå֮ǰµÄ£º
<?page render multiple authors ?>
ËäÈ»Ëü¿´ÉÏÈ¥ºÜÏñXMLÐòÑÔ£¬µ«Êµ¼ÊÉÏÊÇÒ»ÖÖ³ÆΪ´¦ÀíÖ¸Áprocessing instruction£©µÄ²»Í¬ÀàÐ͵ÄÓï·¨¡£´¦ÀíÖ¸ÁÒÔϼò³ÆPI£©µÄÄ¿µÄÊÇΪÁ˸ø´¦ÀíÒ³ÃæµÄ³ÌÐò£¨ÀýÈçXML½âÎöÆ ......
import java.io.File;
import java.io.FileNotFoundException;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
public class ResolveXmlFile {
public void resolverXml() throws DocumentException, FileNotFoundExcept ......