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
Ñ
Ïà¹ØÎĵµ£º
DECLARE @XMLdoc XML
SET @XMLdoc =
'<Book name="SQL Server 2000 Fast Answers">
<Chapters>
<Chapter id="1" name="Installation, Upgrades">
<CreateDate>2009-12-30</CreateDate>
</Chapter>
<Chapter id="2" name="Configuring SQL Server"/>
<Chapter i ......
¡¡¡¡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 ......
ÒýÑÔ
Èç¹ûÄãÒѾ¿´ÁËAsp.Net AjaxµÄÁ½ÖÖ»ù±¾¿ª·¢Ä£Ê½ ÕâƪÎÄÕ£¬Äã¿ÉÄܺܿì»á·¢ÏÖÕâÑùÒ»¸öÎÊÌ⣺ÔÚÄÇƪÎÄÕµķ½Ê½2ÖУ¬¿Í»§¶Ë½ö½öÊÇ·¢ËÍÁËÒ³ÃæÉÏÒ»¸öÎı¾¿òµÄÄÚÈݵ½·þÎñ¶Ë£¬¶ø·þÎñ¶ËµÄWeb·þÎñ·½·¨Ò²Ö»½ÓÊÕÒ»¸öÀ´×Ô¿Í»§¶ËµÄ×Ö·û´®ÀàÐ͵ÄÊýÖµ¡£¶øºÜ¶àʱºò£¬·þÎñ¶ËµÄ·½·¨ÆÚÍû½ÓÊÕµÄÊÇÒ»¸ö×Ô¶¨ÒåÀàÐÍ£¬»òÕßÊǶà¸ö²»Í¬ÀàÐ͵IJÎÊ ......
JavaÓëXMLÁªºÏ±à³ÌÖ®DOMƪ
DOM³õ²½
DOM
ÊÇDocument Object
ModelµÄËõд£¬¼´Îĵµ¶ÔÏóÄ£ÐÍ¡£Ç°Ãæ˵¹ý£¬XML½«Êý¾Ý×é֯Ϊһ¿ÅÊ÷£¬ËùÒÔDOM¾ÍÊǶÔÕâ¿ÅÊ÷µÄÒ»¸ö¶ÔÏóÃèÐð¡£Í¨Ë×µÄ˵£¬¾ÍÊÇͨ¹ý½âÎöXMLÎĵµ£¬Îª
XMLÎĵµÔÚÂß¼ÉϽ¨Á¢Ò»¸öÊ÷Ä£ÐÍ£¬Ê÷µÄ½ÚµãÊÇÒ»¸ö¸ö¶ÔÏó¡£ÎÒÃÇͨ¹ý´æÈ¡ÕâЩ¶ÔÏó¾ÍÄܹ»´æÈ¡XMLÎĵµµÄÄÚÈÝ¡£ ......