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 ......
ʹÓÃdom4j½âÎöXMLʱ£¬Òª¿ìËÙ»ñȡij¸ö½ÚµãµÄÊý¾Ý£¬Ê¹ÓÃXPathÊǸö²»´íµÄ·½·¨£¬dom4jµÄ¿ìËÙÊÖ²áÀïÒ²½¨ÒéʹÓÃÕâÖÖ·½Ê½£¬±êÌⶼдµÄÕâôÀ«Æø£ºPowerful Navigation with XPath£¬ºÇºÇ¡£
·½·¨ÊÇʹÓÃDocumentµÄselectNodes(String XPath)·½·¨£¬´úÂëд·¨£º
List l = doc.selectNodes("//COLS/COL1");
Ö´ÐÐʱȴÅ׳öÒÔÏÂÒì³££º
Exc ......
ÔÎÄÁ´½Ó£ºhttp://www.cnblogs.com/ding0910/archive/2007/07/12/815407.html
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using BX.Interface;
......