Wrox Programmer Forums
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 19th, 2005, 09:23 AM
Registered User
 
Join Date: Apr 2005
Posts: 352
Thanks: 14
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rupen
Default XPath

HI all,
just look at following xml file.
<?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>
  <publication>
      <date>12</date>
      <month>1</month>
      <year>2005</year>
  </publication>
</book>

<book category="CHILDREN">
  <title lang="en">Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</price>
    <publication>
      <date>12</date>
      <month>2</month>
      <year>2005</year>
  </publication>
</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>
    <publication>
      <date>12</date>
      <month>3</month>
      <year>2005</year>
  </publication>
</book>

<book category="WEB">
  <title lang="en">Learning XML</title>
  <author>Erik T. Ray</author>
  <year>2003</year>
  <price>39.95</price>
    <publication>
      <date>12</date>
      <month>4</month>
      <year>2005</year>
  </publication>
</book>

</bookstore>

Now look at following html file:
<html>
<body>
<script type="text/vbscript">

set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("books.xml")

set nodes=xmlDoc.selectNodes("/bookstore/book/publication[month=3]/month | /bookstore/book/author")

for each x in nodes
  document.write("<xmp>")
  document.write(x.xml)
  document.write("</xmp>")
next

</script>
</body>
<!-- | /bookstore/book/publication[month=3]/month
       /bookstore/book/author
       set nodes=xmlDoc.selectNodes("/bookstore/book/publication[month=3]/month | /bookstore/book/author")
                -->
</html>
Now question:
Write XPath for finding "Author" given that "month" is "3"

 
Old April 19th, 2005, 09:35 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I think the expression you are looking for is

/bookstore/book[publication/month=3]/author

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 19th, 2005, 09:43 AM
Registered User
 
Join Date: Apr 2005
Posts: 352
Thanks: 14
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rupen
Default

Superb!!! Thanx..






Similar Threads
Thread Thread Starter Forum Replies Last Post
XPATH pallone XSLT 4 March 3rd, 2008 10:58 AM
Xpath help please rishid XML 1 February 28th, 2007 03:23 AM
XPATH pallone XSLT 4 November 19th, 2006 07:50 PM
XPath help migake XSLT 2 April 21st, 2006 10:49 AM
Xpath Ma7T XSLT 2 August 16th, 2005 07:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.