XPath to select Element by attribute value

I have following XML.

<?xml version="1.0" encoding="UTF-8"?>
    <Employee id="3">
    <Employee id="4">

I want to select Employee element with id="4".

I am using below XPath expression which is not returning anything.


I checked it at http://chris.photobooks.com/xml/default.htm and it says invalid xpath, not sure where is the issue.


You need to remove the / before the [. Predicates (the parts in [ ]) shouldn't have slashes immediately before them. Also, to select the Employee element itself, you should leave off the /text() at the end or otherwise you'd just be selecting the whitespace text values immediately under the Employee element.


Edit: As Jens points out in the comments, // can be very slow because it searches the entire document for matching nodes. If the structure of the documents you're working with is going to be consistent, you are probably best off using a full path, for example:


Try doing this :


As a follow on, you could select "all nodes with a particular attribute" like this:


Need Your Help

rails paperclip default image with S3

ruby-on-rails amazon-s3 storage paperclip

I'm trying to use the default_url in my application but I store the images using S3. I'm not sure what URL I need to put in there or if I have to create a fake image just to get everything up there.

Null pointer Exception - findViewById()

android nullpointerexception oncreate findviewbyid

Can anyone help me to find out what can be the issue with this program.