xmlÑ¡È¡µ¥¸ö½ÚµãÄÚÈݽâ¾ö°ì·¨
XPath Óï·¨
2007-06-05 17:24
XPath Óï·¨
×÷Õß:w3pop.com ·Òë/ÕûÀí:w3pop.com ·¢²¼:2007-04-29 ä¯ÀÀ:674 :: ::
XPath Nodes(½Úµã) XPath Axes
XPath uses path expressions to select nodes or node-sets in an XML document. The node is selected by following a path or steps.
XPath ͨ¹ý·¾¶±í´ïʽ´ÓXMLÎĵµÖÐÑ¡È¡½Úµã»ò½ÚµãÉèÖ᣿ÉÒÔͨ¹ýÒ»ÌõÓï¾ä»òÏàÓ¦µÄ²½ÖèÑ¡È¡Ò»¸ö½Úµã¡£
The XML Example Document
XMLÎĵµÊµÀý
We will use the following XML document in the examples below.
ÎÒÃǽ«ÔÚ½ÓÏÂÀ´µÄÎÄÕÂÖÐÒýÓÃÕâ¸öXMLÎĵµ¡£
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book>
<title lang="eng">Harry Potter</title>
<price>29.99</price>
</book>
<book>
<title lang="eng">Learning XML</title>
<price>39.95</price>
</book>
</bookstore>
Selecting Nodes
Ñ¡È¡½Úµã
XPath uses path expressions to select nodes in an XML document. The node is selected by following a path or steps. The most useful path expressions are listed below:
XPathͨ¹ý·¾¶±í´ïʽÔÚXMLÎĵµÖÐÑ¡È¡½Úµã¡£¿ÉÒÔͨ¹ýÒ»ÌõÓï¾ä»òÏàÓ¦µÄ²½ÖèÑ¡È¡Ò»¸ö½Úµã¡£ÏÂÃæÁгöÁË×ʹÓõÄ·¾¶±í´ïʽ£º
Expression
±í´ïʽ
Description
×¢ÊÍ
nodename
Selects all child nodes of the node
Ñ¡È¡½ÚµãϵÄËùÓÐ×Ó½Úµã
/
Selects from the root node
Ñ¡È¡¸ù½Úµã
//
Selects nodes in the document from the current node that match the selection no matter where they are
Ñ¡È¡ÎĵµÖÐËùÓзûºÏÌõ¼þµÄ½Úµã£¬²»¹Ü¸Ã½ÚµãλÓںδ¦
.
Selects the current node
Ñ¡È¡µ±Ç°½Úµã
..
Selects the parent of the current node
Ñ¡È¡µ¥Ç°½ÚµãµÄ¸¸½Úµã
@
Selects attributes
Ñ¡È¡ÊôÐÔ
Examples
ʵÀý
In the table below we have listed some path expressions and the result of the expressions:
ÔÚÏÂÃæµÄ±í¸ñÖУ¬ÎÒÃÇÁгöÁËһЩ·¾¶±í´ïʽ¼°ÆäÔËÐеĽá¹û£º
Path Expression
±í´ïʽ
Result
½á¹û
bookstore
Selects all the child nodes of the bookstore element
Ñ¡È¡bookstoreÔªËصÄËùÓÐ×Ó½Úµã
/bookstore
Selects the root element bookstore
Ñ
Ïà¹ØÎĵµ£º
Caused by: java.sql.SQLException: ORA-00918: column ambiguously defined
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/ibatis/jpetstore/persistence/sqlmapdao/sql/Item.xml.
--- The error occurred while applying a parameter map.&nbs ......
¡¡¡¡inkfishÔ´´£¬ÇëÎðÉÌÒµÐÔÖÊתÔØ£¬×ªÔØÇë×¢Ã÷À´Ô´£¨http://blog.csdn.net/inkfish
£©¡£
¡¡¡¡PropertySet£¨À´Ô´£ºhttp://blog.csdn.net/inkfish£©
ÊÇÓÉopensymphony×éÖ¯¿ª·¢µÄµÄÒ»¸ö¿ªÔ´ÏîÄ¿£¬µ«ÊÇÄǸöÏîÄ¿ÎĵµÉÙ£¬³¤Ê±¼äûÓиüУ¬¹Ù·½Îĵµ´íÎóÆæ¶à£¬ËùÒÔÏÖÔÚÔÚÏîÄ¿ÖÐʹÓò¢²»¹ã·º¡£µ«Õâ²¢²»·Á°PropertySet³ÉΪһ¸öÓ ......
1¡¢Class.forNameµÄ×÷ÓÃ?ΪʲôҪÓÃ?
´ð£ºµ÷Óø÷ÃÎÊ·µ»ØÒ»¸öÒÔ×Ö·û´®Ö¸¶¨ÀàÃûµÄÀàµÄ¶ÔÏó¡£
2¡¢JdoÊÇʲô?
´ð£ºJDOÊÇJava¶ÔÏó³Ö¾Ã»¯µÄеĹ淶£¬Îªjava data objectµÄ¼ò³Æ,Ò²ÊÇÒ»¸öÓÃÓÚ´æȡijÖÖÊý¾Ý²Ö¿âÖеĶÔÏóµÄ±ê×¼»¯API¡£JDOÌṩÁË͸Ã÷µÄ¶ÔÏó´æ´¢£¬Òò´Ë¶Ô¿ª·¢ÈËÔ±À´Ëµ£¬´æ´¢Êý¾Ý¶ÔÏóÍêÈ«²»ÐèÒª¶îÍâµÄ´úÂ루ÈçJDBC ......
SAX¸ÅÄî
SAXÊÇSimple API for XML
µÄËõд£¬Ëü²¢²»ÊÇÓÉW3C¹Ù·½ËùÌá³öµÄ±ê×¼£¬¿ÉÒÔ˵ÊÇ“Ãñ¼ä”µÄÊÂʵ±ê×¼¡£Êµ¼ÊÉÏ£¬ËüÊÇÒ»ÖÖÉçÇøÐÔÖʵÄÌÖÂÛ²úÎï¡£ËäÈ»Èç´Ë£¬ÔÚXMLÖжÔSAXµÄÓ¦ÓÃË¿ºÁ²»±ÈDOMÉÙ£¬¼¸ºõËùÓеÄXML½âÎöÆ÷¶¼»áÖ§³ÖËü¡£
Óë
DOM±È½Ï¶øÑÔ£¬SAXÊÇÒ»ÖÖÇáÁ¿Ð͵ķ½·¨¡£ÎÒÃÇÖªµÀ£¬ÔÚ´¦ÀíDOMµÄʱºò£¬Î ......
XMLÏÖÔÚÒѾ³ÉΪһÖÖͨÓõÄÊý¾Ý½»»»¸ñʽ,ËüµÄƽ̨ÎÞ¹ØÐÔ,ÓïÑÔÎÞ¹ØÐÔ,ϵͳÎÞ¹ØÐÔ,¸øÊý¾Ý¼¯³ÉÓë½»»¥´øÀ´Á˼«´óµÄ·½±ã¡£¶ÔÓÚXML±¾ÉíµÄÓ﷨֪ʶÓë¼¼Êõϸ½Ú,ÐèÒªÔĶÁÏà¹ØµÄ¼¼ÊõÎÄÏ×,ÕâÀïÃæ°üÀ¨µÄÄÚÈÝÓÐDOM(Document Object Model),DTD(Document Type Definition),SAX(Simple API for XML),XSD(Xml Schema Definition),XSLT(Exten ......