Gerben Jacobs
Gerben Jacobs

Reputation: 4583

How to use XPath on an Array within SimpleXMLElement?

I seem to be running into a problem. Considering the follow XML structure:

<data>
    <row>
        <id>1</id>
        <name>Peter</name>
    </row>
    <row>
        <id>2</id>
        <name>Ryan</name>
    </row>
    <row>
        <id>3</id>
        <name>Mike</name>
    </row>
</data>

It returns a SXE object named "data" which contains an array "row" which consists of more SXE objects.

I'm using XPath and I want to find the row which has "id = 2". But I don't think you can XPath your way through arrays, so what am I to do?

Edit: Oh, I found the answer. You CAN use XPath

$table->xpath('data/row[id=2]')

Upvotes: 0

Views: 417

Answers (1)

Gerben Jacobs
Gerben Jacobs

Reputation: 4583

Oh, I found the answer. You CAN use XPath

$table->xpath('data/row[id=2]')

Upvotes: 1

Related Questions