S
S
scottparker2020-06-13 15:39:29
PHP
scottparker, 2020-06-13 15:39:29

How to return parent tag values ​​when searching by xml?

Good afternoon. To work with xml I use simpleXML,
To search for a value I use

$users->xpath("//users/user/login[text()='test']");

finds respectively the login tag with the value test. But this is not enough, I would like to return the values ​​of the parent tag. is there any way to do this (without a loop)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
scottparker, 2020-06-13
@scottparker

$users->xpath("//users/user/login[text()='test']/ancestor::user");

found this option

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question