views:

49

answers:

2

example XML:

<users> 
  <user id="fakeuserid">

    <password>fakeuserpassword</password>

    <username>fakeusername</username>

  </user>

  <user id="anotherfakeuserid">

    <password>anotherfakeuserpassword</password>

    <username>anotherfakeusername</username>

  </user>
</users>

I would like to be able to access the id attribute and username value of each user. How could I do that? At the moment I am trying it with: /*/user and //user to no avail

Thanks in advance, Toy

A: 

In xpath:

  • userId = '//user/@id'
  • username = '//user/username'

Is this what you're looking for?

Drew Wills
A: 

Use:

/users/user/@id | /users/user/username

Do note the use of the XPath union operator |

Dimitre Novatchev
Dimitri, your idea works, but it returns two sets of values. I am trying to return one recordset with an idfield for use in search results and edit forms. in this case sql might look like: "select * from tblusers" xml equivalent: //user From there I could access all child nodes: user->password,user->username but how would I access the value of the id attribute? Again thanks in advance for the help
Toy
@Toy: If you have access to an `user` element you cantry issuing another XPath expression against this `user` element: `@id`
Dimitre Novatchev