HOME XPath Tutorial - Wilfrid Laurier University

Transcription

XPath TutorialHOMEXPath TutorialXPath HOMEXPath IntroXPath NodesXPath SyntaxXPath AxesXPath OperatorsXPath ExamplesXPath SummaryXPath TutorialSelected ReadingWeb StatisticsWeb GlossaryWeb HostingWeb QualityHelping W3Schools.About W3SchoolsW3Schools ForumReferencesXPath FunctionsW3Schools ForumSITE SEARCHXPath TutorialXPath is a language for finding information in an XMLdocument. XPath is used to navigate through elementsand attributes in an XML document.Password ProtectYour Web PagesXPath is a major element in the W3C's XSLT standard and XQuery and XPointer are both built on XPathexpressions.WEB HOSTING 15 Domain NameRegistrationSave 20 / year!So an understanding of XPath is fundamental to a lot ofadvanced XML usage.UK Domain NamesUK Web HostingAlojamiento WebStart learning XPath!XPath ReferenceAt W3Schools you will find a complete reference of all the built-in functions in XPath 2.0,XQuery 1.0 and XSLT 2.0.XPath FunctionsTable of ContentsBuy UK Domain NamesRegister Domain NamesCheap Domain NamesCheap Web HostingBest Web HostingBulk Domain NamesUK Web HostingPHP MySQL HostingWeb Hosting UKTop 10 Web HostingXPath IntroductionThis chapter explains what XPath is.XPath NodesThis chapter defines the different types of nodes in XPath and the relationship of nodes.XPath SyntaxThis chapter explains the XPath syntax.XPath AxesThis chapter explains the XPath axes.XPath OperatorsThis chapter lists the operators that can be used in XPath expressions.Web Hosting ProvidersASP.NET Web Hosting3 Months Free!Programming ForumsWindows Web HostingWEB BUILDINGXML Website ToolsWebsite TemplatesFlash TemplatesWebsite BuilderInternet BusinessOpportunityCustom ProgrammingBEST Flash TemplatesXPath ExamplesThis chapter uses the "books.xml" document to demonstrate some XPath examples.http://www.w3schools.com/xpath/ (1 of 4) [3/14/2007 1:03:20 PM]Web Design ForumProgramming Forum

XPath TutorialXPath SummaryThis chapter contains a summary on what you have learned in this tutorial and arecommendation on what subject you should study next.XPath ReferenceXPath FunctionsThis reference library defines the built-in functions required for XPath 2.0, XQuery 1.0 andXSLT 2.0.Your browser does not support inline frames or is currently configured not to display inlineframes.What do you want your Web site to do?What do you want your Web site to do? Ektron CMS400.NET lets you do everything youneed to do on the Web and do everything you want to do.Ektron CMS400.NET gives you all the features you would expect from anenterprise CMS, but also high-demand functionality like real-time Website analytics, community building, blogging, personalization, and onlinecalendars. Ektron CMS400.NET bridges your Web site gaps.Use Ektron CMS400.NET for: Content & Document Management - Author/edit content,manage navigation, menus, audit trails, workflow, approvalsPersonalzation & Portal Support - Allow visitors to create their own view of yourweb page508 & W3C Compliance Checker - Ensure compliance with scheduled or on-demandcompliance reportsMemberships - Build online communties with blogs and forums, enable email webalerts, build polls and surveysWeb Site Analytics - track visitors, report on most requested pages, see where theycame from and where they are goingHTML Form Engine - Create a two-way dialog with visitors using our wizard-likeHTML form-building engine with validation and database supportMultilingual Support - Integrated translation tools help you reach multiple audiencesby speaking their languageOnline Calendars - Build and manage Web-based calendars and enable users tocustomize a view based on what’s important to themSee why there are 15,000 Ektron integrations worldwide.Click here to learn more, then request a live online demo or download a FREE TRIALhttp://www.w3schools.com/xpath/ (2 of 4) [3/14/2007 1:03:20 PM]FREE Trial or DemoWeb Content ManagerForms,Web Alerts,RSSHTML ExamSHOPPINGUK WholesalersUK WholesaleONLINE DEGREEAdvance Your Careerwith Drexel UniversityBachelor's & Master'sTech Degrees ONLINE

Introduction to XPathHOMEXPath TutorialXPath HOMEXPath IntroXPath NodesXPath SyntaxXPath AxesXPath OperatorsXPath ExamplesXPath SummaryReferencesXPath FunctionsSelected ReadingWeb StatisticsWeb GlossaryWeb HostingWeb QualityXPath IntroductionSITE SEARCH.About W3SchoolsW3Schools ForumXPath is a language for finding information in an XML document. XPath is used tonavigate through elements and attributes in an XML document.What You Should Already KnowBefore you continue you should have a basic understanding of the following: HTML / XHTMLXML / XML NamespacesIf you want to study these subjects first, find the tutorials on our Home page.W3Schools ForumHelping W3SchoolsPassword ProtectYour Web PagesWEB HOSTING 15 Domain NameRegistrationSave 20 / year!UK Domain NamesUK Web HostingAlojamiento WebBuy UK Domain NamesRegister Domain NamesCheap Domain NamesCheap Web HostingBest Web HostingWhat is XPath?Bulk Domain NamesUK Web Hosting XPathXPathXPathXPathXPathis a syntax for defining parts of an XML documentuses path expressions to navigate in XML documentscontains a library of standard functionsis a major element in XSLTis a W3C StandardPHP MySQL HostingWeb Hosting UKTop 10 Web HostingWeb Hosting ProvidersASP.NET Web Hosting3 Months Free!XPath Path ExpressionsXPath uses path expressions to select nodes or node-sets in an XML document. These pathexpressions look very much like the expressions you see when you work with a traditionalcomputer file system.XPath Standard FunctionsXPath includes over 100 built-in functions. There are functions for string values, numericvalues, date and time comparison, node and QName manipulation, sequence manipulation,Boolean values, and more.http://www.w3schools.com/xpath/xpath intro.asp (1 of 3) [3/14/2007 1:01:58 PM]Programming ForumsWindows Web HostingWEB BUILDINGXML Website ToolsWebsite TemplatesFlash TemplatesWebsite BuilderInternet BusinessOpportunityCustom ProgrammingBEST Flash TemplatesWeb Design ForumProgramming Forum

Introduction to XPathXPath is Used in XSLTXPath is a major element in the XSLT standard. Without XPath knowledge you will not be ableto create XSLT documents.You can read more about XSLT in our XSLT tutorial.XQuery and XPointer are both built on XPath expressions. XQuery 1.0 and XPath 2.0 share thesame data model and support the same functions and operators.You can read more about XQuery in our XQuery tutorial.XPath is a W3C StandardXPath became a W3C Recommendation 16. November 1999.XPath was designed to be used by XSLT, XPointer and other XML parsing software.You can read more about the XPath standard in our W3C tutorial.Your browser does not support inline frames or is currently configured not to display inlineframes.What do you want your Web site to do?What do you want your Web site to do? Ektron CMS400.NET lets you do everything youneed to do on the Web and do everything you want to do.Ektron CMS400.NET gives you all the features you would expect from anenterprise CMS, but also high-demand functionality like real-time Website analytics, community building, blogging, personalization, and onlinecalendars. Ektron CMS400.NET bridges your Web site gaps.Use Ektron CMS400.NET for: Content & Document Management - Author/edit content,manage navigation, menus, audit trails, workflow, approvalsPersonalzation & Portal Support - Allow visitors to create their own view of yourweb pagehttp://www.w3schools.com/xpath/xpath intro.asp (2 of 3) [3/14/2007 1:01:58 PM]FREE Trial or DemoWeb Content ManagerForms,Web Alerts,RSSHTML ExamSHOPPINGUK WholesalersUK WholesaleONLINE DEGREEAdvance Your Careerwith Drexel UniversityBachelor's & Master'sTech Degrees ONLINE

XPath NodesHOMEXPath TutorialXPath HOMEXPath IntroXPath NodesXPath SyntaxXPath AxesXPath OperatorsXPath ExamplesXPath SummaryReferencesXPath FunctionsSelected ReadingWeb StatisticsWeb GlossaryWeb HostingWeb QualityW3Schools ForumSITE SEARCHXPath Nodes.About W3SchoolsW3Schools ForumIn XPath, there are seven kinds of nodes: element, attribute, text, namespace,processing-instruction, comment, and document (root) nodes.ASP.NETShopping CartWEB HOSTING 15 Domain NameRegistrationSave 20 / year!XPath TerminologyNodesIn XPath, there are seven kinds of nodes: element, attribute, text, namespace, processinginstruction, comment, and document (root) nodes. XML documents are treated as trees ofnodes. The root of the tree is called the document node (or root node).UK Domain NamesUK Web HostingAlojamiento WebBuy UK Domain NamesRegister Domain NamesCheap Domain NamesCheap Web HostingLook at the following XML document:Helping W3Schools ?xml version "1.0" encoding "ISO-8859-1"? Best Web HostingBulk Domain NamesUK Web Hosting bookstore book title lang "en" Harry Potter /title author J K. Rowling /author year 2005 /year price 29.99 /price /book Example of nodes in the XML document above:(document node) author J K. Rowling /author lang "en"Top 10 Web HostingWeb Hosting ProvidersASP.NET Web Hosting3 Months Free!Programming ForumsWindows Web Hosting /bookstore bookstore PHP MySQL HostingWeb Hosting UK(attribute node)(element node)WEB BUILDINGXML Website ToolsWebsite TemplatesFlash TemplatesWebsite BuilderInternet BusinessOpportunityCustom ProgrammingBEST Flash TemplatesAtomic valueshttp://www.w3schools.com/xpath/xpath nodes.asp (1 of 4) [3/14/2007 1:08:15 PM]Web Design ForumProgramming Forum

XPath NodesAtomic values are nodes with no children or parent.Example of atomic values:FREE Trial or DemoWeb Content ManagerForms,Web Alerts,RSSHTML ExamJ K. Rowling"en"ItemsItems are atomic values or nodes.Relationship of NodesParentEach element and attribute has one parent.In the following example; the book element is the parent of the title, author, year, and price: book title Harry Potter /title author J K. Rowling /author year 2005 /year price 29.99 /price /book ChildrenElement nodes may have zero, one or more children.In the following example; the title, author, year, and price elements are all children of thebook element: book title Harry Potter /title author J K. Rowling /author year 2005 /year price 29.99 /price /book SiblingsNodes that have the same parent.In the following example; the title, author, year, and price elements are all siblings:http://www.w3schools.com/xpath/xpath nodes.asp (2 of 4) [3/14/2007 1:08:15 PM]SHOPPINGUK WholesalersUK WholesaleONLINE DEGREEAdvance Your Careerwith Drexel UniversityBachelor's & Master'sTech Degrees ONLINE

XPath Nodes book title Harry Potter /title author J K. Rowling /author year 2005 /year price 29.99 /price /book AncestorsA node's parent, parent's parent, etc.In the following example; the ancestors of the title element are the book element and thebookstore element: bookstore book title Harry Potter /title author J K. Rowling /author year 2005 /year price 29.99 /price /book /bookstore DescendantsA node's children, children's children, etc.In the following example; descendants of the bookstore element are the book, title, author,year, and price elements: bookstore book title Harry Potter /title author J K. Rowling /author year 2005 /year price 29.99 /price /book /bookstore Your browser does not support inline frames or is currently configured not to display inlineframes.Learn XML with Stylus Studio XML Tools - Free Download!http://www.w3schools.com/xpath/xpath nodes.asp (3 of 4) [3/14/2007 1:08:15 PM]

XPath SyntaxHOMEXPath TutorialXPath HOMEXPath IntroXPath NodesXPath SyntaxXPath AxesXPath OperatorsXPath ExamplesXPath SummaryReferencesXPath FunctionsSelected ReadingWeb StatisticsWeb GlossaryWeb HostingWeb QualityXPath Syntax.About W3SchoolsW3Schools ForumXPath uses path expressions to select nodes or node-sets in an XML document. Thenode is selected by following a path or steps.The XML Example DocumentWe will use the following XML document in the examples below. ?xml version "1.0" encoding "ISO-8859-1"? Active Server PagesResource Web SiteWEB HOSTING 15 Domain NameRegistrationSave 20 / year!UK Domain NamesUK Web HostingAlojamiento WebBuy UK Domain NamesRegister Domain Names bookstore W3Schools ForumHelping W3SchoolsSITE SEARCH book title lang "eng" Harry Potter /title price 29.99 /price /book Cheap Domain NamesCheap Web HostingBest Web HostingBulk Domain NamesUK Web Hosting book title lang "eng" Learning XML /title price 39.95 /price /book PHP MySQL HostingWeb Hosting UKTop 10 Web HostingWeb Hosting Providers /bookstore ASP.NET Web Hosting3 Months Free!Selecting NodesXPath uses path expressions to select nodes in an XML document. The node is selected byfollowing a path or steps. The most useful path expressions are listed below:ExpressionDescriptionnodenameSelects all child nodes of the node/Selects from the root node//Selects nodes in the document from the current node that match theselection no matter where they are.Selects the current node.Selects the parent of the current nodehttp://www.w3schools.com/xpath/xpath syntax.asp (1 of 5) [3/14/2007 1:08:27 PM]Programming ForumsWindows Web HostingWEB BUILDINGXML Website ToolsWebsite TemplatesFlash TemplatesWebsite BuilderInternet BusinessOpportunityCustom ProgrammingBEST Flash TemplatesWeb Design ForumProgramming Forum

XPath Syntax@Selects attributesFREE Trial or DemoWeb Content ManagerForms,Web Alerts,RSSExamplesHTML ExamIn the table below we have listed some path expressions and the result of the expressions:Path ExpressionResultbookstoreSelects all the child nodes of the bookstore element/bookstoreSelects the root element bookstoreNote: If the path starts with a slash ( / ) it always represents anabsolute path to an element!bookstore/bookSelects all book elements that are children of bookstore//bookSelects all book elements no matter where they are in thedocumentbookstore//bookSelects all book elements that are descendant of the bookstoreelement, no matter where they are under the bookstore element//@langSelects all attributes that are named langPredicatesPredicates are used to find a specific node or a node that contains a specific value.Predicates are always embedded in square brackets.ExamplesIn the table below we have listed some path expressions with predicates and the result of theexpressions:Path ExpressionResult/bookstore/book[1]Selects the first book element that is the childof the bookstore element/bookstore/book[last()]Selects the last book element that is the childof the bookstore element/bookstore/book[last()-1]Selects the last but one book element that isthe child of the bookstore element/bookstore/book[position() 3]Selects the first two book elements that arechildren of the bookstore element//title[@lang]Selects all the title elements that have anattribute named lang//title[@lang 'eng']Selects all the title elements that have anattribute named lang with a value of 'eng'/bookstore/book[price 35.00]Selects all the book elements of the bookstoreelement that have a price element with avalue greater than 35.00/bookstore/book[price 35.00]/titleSelects all the title elements of the bookelements of the bookstore element that havea price element with a value greater than35.00http://www.w3schools.com/xpath/xpath syntax.asp (2 of 5) [3/14/2007 1:08:27 PM]SHOPPINGUK WholesalersUK WholesaleONLINE DEGREEAdvance Your Careerwith Drexel UniversityBachelor's & Master'sTech Degrees ONLINE

XPath SyntaxSelecting Unknown NodesXPath wildcards can be used to select unknown XML elements.WildcardDescription*Matches any element node@*Matches any attribute nodenode()Matches any node of any kindExamplesIn the table below we have listed some path expressions and the result of the expressions:Path ExpressionResult/bookstore/*Selects all the child nodes of the bookstore element//*Selects all elements in the document//title[@*]Selects all title elements which have any attributeSelecting Several PathsBy using the operator in an XPath expression you can select several paths.ExamplesIn the table below we have listed some path expressions and the result of the expressions:Path ExpressionResult//book/title //book/priceSelects all the title AND price elements of all bookelements//title //priceSelects all the title AND price elements in the document/bookstore/book/title //priceSelects all the title elements of the book element of thebookstore element AND all the price elements in thedocumentYour browser does not support inline frames or is currently configured not to display inlineframes.What do you want your Web site to do?http://www.w3schools.com/xpath/xpath syntax.asp (3 of 5) [3/14/2007 1:08:27 PM]

XPath AxesHOMEXPath TutorialXPath HOMEXPath IntroXPath NodesXPath SyntaxXPath AxesXPath OperatorsXPath ExamplesXPath SummaryReferencesXPath FunctionsSITE SEARCHXPath Axes.About W3SchoolsW3Schools ForumThe XML Example DocumentWe will use the following XML document in the examples below. ?xml version "1.0" encoding "ISO-8859-1"? bookstore Selected ReadingWeb StatisticsWeb GlossaryWeb HostingWeb Quality book title lang "eng" Harry Potter /title price 29.99 /price /book W3Schools ForumHelping W3Schools book title lang "eng" Learning XML /title price 39.95 /price /book Active Server PagesResource Web SiteWEB HOSTING 15 Domain NameRegistrationSave 20 / year!UK Domain NamesUK Web HostingAlojamiento WebBuy UK Domain NamesRegister Domain NamesCheap Domain NamesCheap Web HostingBest Web HostingBulk Domain NamesUK Web HostingPHP MySQL HostingWeb Hosting UK /bookstore Top 10 Web HostingXPath AxesWeb Hosting ProvidersAn axis defines a node-set relative to the current node.ASP.NET Web Hosting3 Months Free!Programming ForumsWindows Web HostingAxisNameResultancestorSelects all ancestors (parent, grandparent, etc.) of thecurrent nodeancestor-or-selfSelects all ancestors (parent, grandparent, etc.) of thecurrent node and the current node itselfattributeSelects all attributes of the current nodechildSelects all children of the current nodedescendantSelects all descendants (children, grandchildren, etc.) ofthe current nodedescendant-or-selfSelects all descendants (children, grandchildren, etc.) ofthe current node and the current node itselfBEST Flash TemplatesfollowingSelects everything in the document after the closing tagof the current nodeWeb Design ForumProgramming Forumhttp://www.w3schools.com/xpath/xpath axes.asp (1 of 4) [3/14/2007 1:08:39 PM]WEB BUILDINGXML Website ToolsWebsite TemplatesFlash TemplatesWebsite BuilderInternet BusinessOpportunityCustom Programming

XPath Axesfollowing-siblingSelects all siblings after the current nodenamespaceSelects all namespace nodes of the current nodeparentSelects the parent of the current nodeprecedingSelects everything in the document that is before thestart tag of the current nodepreceding-siblingSelects all siblings before the current nodeselfSelects the current nodeLocation Path ExpressionA location path can be absolute or relative.An absolute location path starts with a slash ( / ) and a relative location path does not. In bothcases the location path consists of one or more steps, each separated by a slash:An absolute location path:/step/step/.A relative location path:step/step/.Each step is evaluated against the nodes in the current node-set.A step consists of: an axis (defines the tree-relationship between the selected nodes and the currentnode)a node-test (identifies a node within an axis)zero or more predicates (to further refine the selected node-set)The syntax for a location step ultchild::bookSelects all book nodes that are children of the currentnodeattribute::langSelects the lang attribute of the current nodechild::*Selects all children of the current nodeattribute::*Selects all attributes of the current nodechild::text()Selects all text child nodes of the current nodechild::node()Selects all child nodes of the current nodedescendant::bookSelects all book descendants of the current nodehttp://www.w3schools.com/xpath/xpath axes.asp (2 of 4) [3/14/2007 1:08:39 PM]FREE Trial or DemoWeb Content ManagerForms,Web Alerts,RSSHTML ExamSHOPPINGUK WholesalersUK WholesaleONLINE DEGREEAdvance Your Careerwith Drexel UniversityBachelor's & Master'sTech Degrees ONLINE

XPath Axesancestor::bookSelects all book ancestors of the current nodeancestor-or-self::bookSelects all book ancestors of the current node - and thecurrent as well if it is a book nodechild::*/child::priceSelects all price grandchildren of the current nodeYour browser does not support inline frames or is currently configured not to display inlineframes.What do you want your Web site to do?What do you want your Web site to do? Ektron CMS400.NET lets you do everything youneed to do on the Web and do everything you want to do.Ektron CMS400.NET gives you all the features you would expect from anenterprise CMS, but also high-demand functionality like real-time Website analytics, community building, blogging, personalization, and onlinecalendars. Ektron CMS400.NET bridges your Web site gaps.Use Ektron CMS400.NET for: Content & Document Management - Author/edit content,manage navigation, menus, audit trails, workflow, approvalsPersonalzation & Portal Support - Allow visitors to create their own view of yourweb page508 & W3C Compliance Checker - Ensure compliance with scheduled or on-demandcompliance reportsMemberships - Build online communties with blogs and forums, enable email webalerts, build polls and surveysWeb Site Analytics - track visitors, report on most requested pages, see where theycame from and where they are goingHTML Form Engine - Create a two-way dialog with visitors using our wizard-likeHTML form-building engine with validation and database supportMultilingual Support - Integrated translation tools help you reach multiple audiencesby speaking their languageOnline Calendars - Build and manage Web-based calendars and enable users tocustomize a view based on what’s important to themSee why there are 15,000 Ektron integrations worldwide.Click here to learn more, then request a live online demo or download a FREE TRIALhttp://www.w3schools.com/xpath/xpath axes.asp (3 of 4) [3/14/2007 1:08:39 PM]

XPath OperatorsHOMEXPath TutorialXPath HOMEXPath IntroXPath NodesXPath SyntaxXPath AxesXPath OperatorsXPath ExamplesXPath SummaryReferencesXPath FunctionsSelected ReadingWeb StatisticsWeb GlossaryWeb HostingWeb QualityW3Schools ForumHelping W3SchoolsSITE SEARCHXPath Operators.About W3SchoolsW3Schools ForumAn XPath expression returns either a node-set, a string, a Boolean, or a number.Active Server PagesResource Web SiteWEB HOSTING 15 Domain NameRegistrationSave 20 / year!XPath OperatorsBelow is a list of the operators that can be used in XPath expressions:OperatorDescriptionExampleReturn value Computes two node-sets//book //cdReturns a node-setwith all book and cdelements Addition6 410-Subtraction6-42UK Domain NamesUK Web HostingAlojamiento WebBuy UK Domain NamesRegister Domain NamesCheap Domain NamesCheap Web Hosting*Multiplication6*424divDivision8 div 42 Equalprice 9.80true if price is 9.80false if price is 9.90! Not equalprice! 9.80true if price is 9.90false if price is 9.80 Less thanprice 9.80true if price is 9.00false if price is 9.80 Less than or equal toprice 9.80true if price is 9.00false if price is 9.90 Greater thanprice 9.80true if price is 9.90false if price is 9.80 Greater than or equal toprice 9.80true if price is 9.90false if price is 9.70Programming ForumsWindows Web Hostingororprice 9.80 or price 9.70true if price is 9.80false if price is 9.50WEB BUILDINGXML Website Toolsandandprice 9.00 and price 9.90 true if price is 9.80false if price is 8.50modModulus (divisionremainder)5 mod 2Website TemplatesFlash TemplatesWebsite BuilderInternet BusinessOpportunity1Best Web HostingBulk Domain NamesUK Web HostingPHP MySQL HostingWeb Hosting UKTop 10 Web HostingWeb Hosting ProvidersASP.NET Web Hosting3 Months Free!Custom ProgrammingBEST Flash TemplatesYour browser does not support inline frames or is currently configured not to display inlineframes.http://www.w3schools.com/xpath/xpath operators.asp (1 of 3) [3/14/2007 1:08:52 PM]Web Design ForumProgramming Forum

XPath ExamplesHOMEXPath TutorialXPath HOMEXPath IntroXPath NodesXPath SyntaxXPath AxesXPath OperatorsXPath ExamplesXPath SummaryReferencesXPath FunctionsSelected ReadingWeb StatisticsWeb GlossaryWeb HostingWeb QualityW3Schools ForumHelping W3SchoolsXPath ExamplesSITE SEARCH.About W3SchoolsW3Schools ForumLet's try to learn some basic XPath syntax by looking at some examples.Web based chartingfor ASP.NETThe XML Example DocumentWe will use the following XML document in the examples below."books.xml": ?xml version "1.0" encoding "ISO-8859-1"? bookstore book category "COOKING" title lang "en" Everyday Italian /title author Giada De Laurentiis /author year 2005 /year price 30.00 /price /book book category "CHILDREN" title lang "en" Harry Potter /title author J K. Rowling /author year 2005 /year price 29.99 /price /book book category "WEB" title lang "en" XQuery Kick Start /title author James McGovern /author author Per Bothner /author author Kurt Cagle /author author James Linn /author author Vaidyanathan Nagarajan /author year 2003 /year price 49.99 /price /book book category "WEB" http://www.w3schools.com/xpath/xpath examples.asp (1 of 4) [3/14/2007 1:09:03 PM]WEB HOSTING 15 Domain NameRegistrationSave 20 / year!UK Domain NamesUK Web HostingAlojamiento WebBuy UK Domain NamesRegister Domain NamesCheap Domain NamesCheap Web HostingBest Web HostingBulk Domain NamesUK Web HostingPHP MySQL HostingWeb Hosting UKTop 10 Web HostingWeb Hosting ProvidersASP.NET Web Hosting3 Months Free!Programming ForumsWindows Web HostingWEB BUILDINGXML Website ToolsWebsite TemplatesFlash TemplatesWebsite BuilderInternet BusinessOpportunityCustom ProgrammingBEST Flash TemplatesWeb Design ForumProgramming Forum

XPath Examples title lang "en" Learning XML /title author Erik T. Ray /author year 2003 /year price 39.95 /price /book /bookstore View the "books.xml" file in your browser.Selecting NodesWe will use the Microsoft XMLDOM object to load the XML document and the selectNodes()function to select nodes from the XML document:set xmlDoc CreateObject("Microsoft.XMLDOM")xmlDoc.async path expression)Select all book NodesThe following example selects all the book nodes under the bookstore element:xmlDoc.selectNodes("/bookstore/book")If you have IE 5 or higher you can try it yourself.Select the First book NodeThe following example selects only the first book node under the bookstore element:xmlDoc.selectNodes("/bookstore/book[0]")If you have IE 5 or higher you can try it yourselfNote: IE5 and later has implemented that [0] should be the first node, but according to theW3C standard it should have been [1]!!A Workaround!To solve the [0] and [1] problem in IE5 , you can set the SelectionLanguage to XPath.http://www.w3schools.com/xpath/xpath examples.asp (2 of 4) [3/14/2007 1:09:03 PM]FREE Trial or DemoWeb Content ManagerForms,Web Alerts,RSSHTML ExamSHOPPINGUK WholesalersUK WholesaleONLINE DEGREEAdvance Your Careerwith Drexel UniversityBachelor's & Master'sTech Degrees ONLINE

XPath ExamplesThe following example selects only the first book node under the bookstore element:xmlDoc.setProperty "SelectionLanguage", "XPath"xmlDoc.selectNodes("/bookstore/book[1]")Try it yourselfSelect the pricesThe following example selects the text from all the price xt()")If you have IE 5 or higher you can try it yourself.Selecting price Nodes with Price 35The following example selects all the price nodes with a price higher than 35:xmlDoc.selectNodes("/bookstore/book[price 35]/price")If you have IE 5 or higher you can try it yourself.Selecting title Nodes with Price 35The following example selects all the title nodes with a price higher than 35:xmlDoc.selectNodes("/bookstore/book[price 35]/title")If you have IE 5 or higher you can try it yourself.Your browser does not support inline frames or is currently configured not to display inlineframes.Want To Be A Web Master?If you want to be a Web Master, you will have to host your web site with an ISP (InternetService Provider).http://www.w3schools.com/xpath/xpath examples.asp (3 of 4) [3/14/2007 1:09:03 PM]

Ektron CMS400.NET gives you all the features you would expect from an enterprise CMS, but also high-demand functionality like real-time Web site analytics, community building, blogging, personalization, and online calendars. Ektron CMS400.NET bridges your Web site gaps. Use Ektron CMS400.NET for: Content & Document Management - Author/edit content,