开发者

Simplexml xpath to attribute value and and child node values in one query

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


Use:

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

Do note the use of the XPath union operator |


In xpath:

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

Is this what you're looking for?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜