Connecting Tech Pros Worldwide Forums | Help | Site Map

Get all attributes, XPATH

Newbie
 
Join Date: Jul 2009
Posts: 2
#1: Jul 20 '09
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>

Newbie
 
Join Date: Jul 2009
Posts: 2
#2: Jul 20 '09

re: Get all attributes, XPATH


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
Newbie
 
Join Date: Jul 2009
Posts: 2
#3: Jul 21 '09

re: Get all attributes, XPATH


then your expression would get all elements :), thanks
Newbie
 
Join Date: Jul 2009
Posts: 2
#4: Jul 21 '09

re: Get all attributes, XPATH


Well after getting all the needed nodes then you can select the attributes:

Expand|Select|Wrap|Line Numbers
  1. "//*[starts-with(@ID,'ext')]/@*"
Moderator
 
Join Date: Mar 2006
Posts: 1,103
#5: Jul 22 '09

re: Get all attributes, XPATH


//@*[starts-with(../@ID,'ext')]
Reply


Similar XML bytes