Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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
Ñ


Ïà¹ØÎĵµ£º

springÖжÁÈ¡xmlÅäÖÃÎļþ¡¢»ñÈ¡beanµÄ¼¸ÖÖ·½Ê½

»ñÈ¡Spring¿ò¼Ü¹ÜÀíµÄÀàʵÀýµÄ·½·¨ÓжàÖÖ,ÈçÏ£º
·½·¨Ò»£ºÔÚ³õʼ»¯Ê±±£´æApplicationContext¶ÔÏó
´úÂ룺
ApplicationContext ac = new FileSystemXmlApplicationContext("applicationContext.xml");
ac.getBean("beanId");
˵Ã÷£º
ÕâÖÖ·½Ê½ÊÊÓÃÓÚ²ÉÓÃSpring¿ò¼ÜµÄ¶ÀÁ¢Ó¦ÓóÌÐò£¬ÐèÒª³ÌÐòͨ¹ýÅäÖÃÎļþÊÖ¹¤³õʼ»¯ ......

´ÓÒ»¸ö·¶Àý¿´XMLµÄÓ¦ÓÃ

ÒýÑÔ
Èç¹ûÄãÒѾ­¿´ÁËAsp.Net AjaxµÄÁ½ÖÖ»ù±¾¿ª·¢Ä£Ê½ ÕâƪÎÄÕ£¬Äã¿ÉÄܺܿì»á·¢ÏÖÕâÑùÒ»¸öÎÊÌ⣺ÔÚÄÇƪÎÄÕµķ½Ê½2ÖУ¬¿Í»§¶Ë½ö½öÊÇ·¢ËÍÁËÒ³ÃæÉÏÒ»¸öÎı¾¿òµÄÄÚÈݵ½·þÎñ¶Ë£¬¶ø·þÎñ¶ËµÄWeb·þÎñ·½·¨Ò²Ö»½ÓÊÕÒ»¸öÀ´×Ô¿Í»§¶ËµÄ×Ö·û´®ÀàÐ͵ÄÊýÖµ¡£¶øºÜ¶àʱºò£¬·þÎñ¶ËµÄ·½·¨ÆÚÍû½ÓÊÕµÄÊÇÒ»¸ö×Ô¶¨ÒåÀàÐÍ£¬»òÕßÊǶà¸ö²»Í¬ÀàÐ͵IJÎÊ ......

MsXml´´½¨ºÍ½âÎöXMLʾÀý

Ò»£®MsXml´´½¨XMLÎĵµÊ¾Àý
 // XmlCreationDemo.cpp
#include <stdlib.h>
#include <stdio.h>
// ÒýÈëMSXML½âÎöÆ÷
#import <msxml4.dll>
using namespace MSXML2;
class InitializeCom
{
public:
InitializeCom() { CoInitialize(NULL); // Initializes the COM library }
~Initializ ......

[¼¼Êõѧϰ]C++ XML¿â£¨×ªÔØ£©

ÔÚC++ÖУ¬¿âµÄµØλÊǷdz£¸ßµÄ¡£C++Ö®¸¸ Bjarne StroustrupÏÈÉú¶à´Î±íʾÁËÉè¼Æ¿âÀ´À©³ä¹¦ÄÜÒªºÃ¹ýÉè¼Æ¸ü¶àµÄÓï·¨µÄÑÔÂÛ¡£ÏÖʵÖУ¬C++µÄ¿âÃÅÀà·±¶à£¬½â¾öµÄÎÊÌâÒ²ÊǼ«Æä¹ã·º£¬¿â´ÓÇáÁ¿¼¶µ½ÖØÁ¿¼¶µÄ¶¼ÓС£²»ÉÙ¶¼ÊÇÈÃÈËÑÛ½ç´ó¿ª£¬Òà»òÊÇÍû¶øÉú̾µÄ˼ά½Ü×÷¡£ÓÉÓÚ¿âµÄÊýÁ¿·Ç³£ÅӴ󣬶øÇÒÏÞÓÚ±ÊÕßˮƽ£¬ÆäÖкܶಢ²»Á˽⡣ËùÒÔÎÄÖ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ