Get all attributes, XPATH

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hose
    New Member
    • Jul 2009
    • 2

    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 :(
    Code:
    //@*[starts-with(@ID,"ext")]
    Below is my XML file
    Code:
    <?xml version="1.0"?>
    <books>
    	<book ID="extension1" available="yes">
    		<title>Book Title 1</title>
    		<price>100 - 200</price>
    	</book>
    	<book ID="Book001" available="no">
    		<title>Book Title 2</title>
    		<price>400 - 500</price>
    	</book>
    	<book ID="extension2">
    		<title>Book Title 3</title>
    		<price>abc - 500</price>
    	</book>
    	<book available="soon">
    		<title>Book Title 5</title>
    		<price>a100 - c200</price>
    	</book>
    	<book ID="Book003" available="yes">
    		<title>Book Title 6</title>
    		<price>c100 - 200</price>
    	</book>
    </books>
  • arsya
    New Member
    • Jul 2009
    • 2

    #2
    There is a mistake in your xpath expression. The correct one is like the following:
    Code:
    //*[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

    Comment

    • hose
      New Member
      • Jul 2009
      • 2

      #3
      then your expression would get all elements :), thanks

      Comment

      • arsya
        New Member
        • Jul 2009
        • 2

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

        Code:
        "//*[starts-with(@ID,'ext')]/@*"

        Comment

        • jkmyoung
          Recognized Expert Top Contributor
          • Mar 2006
          • 2057

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

          Comment

          Working...