469,314 Members | 2,138 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,314 developers. It's quick & easy.

Get all attributes, XPATH

2
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 13318
arsya
2
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
hose
2
then your expression would get all elements :), thanks
Jul 20 '09 #3
arsya
2
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
jkmyoung
2,057 Expert 2GB
//@*[starts-with(../@ID,'ext')]
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
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.