A
A
Ayk722015-11-03 12:19:50
PHP
Ayk72, 2015-11-03 12:19:50

How to select in xml?

Good afternoon!
How to select a specific id in an xml file?
Example:

<user>
<id>1</id>
...
</user>
<user>
<id>2</id>
...
</user>

How can I select data with user id 1?
Now I'm getting all the data like this:
$file = $_SERVER['DOCUMENT_ROOT']."/file/1-10/1 (4).xml";
$xml = simplexml_load_file($file);

foreach ($xml->user as $user) {
$user->id;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
krypt3r, 2015-11-03
@krypt3r

Something like an XPath query
where users is your root element

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question