472,131 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,131 software developers and data experts.

Get all attributes, XPATH

Dear All, I am getting stuck with this for a few days :(
and about to decide to give up or find an alternative, but I want to give it a last try :(

My question is how can we write an Xpath expression to get all attributes from an element with ID begins with "ext"

I have tried something like blow, but did not work :(
Expand|Select|Wrap|Line Numbers
  1. //@*[starts-with(@ID,"ext")]
Below is my XML file
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <books>
  3.     <book ID="extension1" available="yes">
  4.         <title>Book Title 1</title>
  5.         <price>100 - 200</price>
  6.     </book>
  7.     <book ID="Book001" available="no">
  8.         <title>Book Title 2</title>
  9.         <price>400 - 500</price>
  10.     </book>
  11.     <book ID="extension2">
  12.         <title>Book Title 3</title>
  13.         <price>abc - 500</price>
  14.     </book>
  15.     <book available="soon">
  16.         <title>Book Title 5</title>
  17.         <price>a100 - c200</price>
  18.     </book>
  19.     <book ID="Book003" available="yes">
  20.         <title>Book Title 6</title>
  21.         <price>c100 - 200</price>
  22.     </book>
  23. </books>
Jul 20 '09 #1
4 14208
There is a mistake in your xpath expression. The correct one is like the following:
Expand|Select|Wrap|Line Numbers
  1. //*[starts-with(@ID,'ext')]
If you need an example of using the xpath starts-with function in Python, see the example #2 in this http://murzal-arsya.blogspot.com/200...hon-using.html
Jul 20 '09 #2
then your expression would get all elements :), thanks
Jul 20 '09 #3
Well after getting all the needed nodes then you can select the attributes:

Expand|Select|Wrap|Line Numbers
  1. "//*[starts-with(@ID,'ext')]/@*"
Jul 21 '09 #4
2,057 Expert 2GB
Jul 22 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by mark.van.der.voort | last post: by
1 post views Thread by Dave Lech | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.