user2194875
user2194875

Reputation: 31

Parse XML with a colon attribute in PHP

I'd have the following XML structure:

<entry>
    <id im:id="595831580">blabla</id>
</entry>

Now I want to parse the id 595831580.

I tried:

$idAtt = $xml->entry->id;
$id = $idAtt->attributes();
$id2 = $id['im:id'];

But this does not work :(

How can I fix it?

Upvotes: 3

Views: 2782

Answers (2)

Passerby
Passerby

Reputation: 10080

Alright.

You can't use namespace in offsetGet method of SimpleXMLElement, but you can in attributes method:

echo $xml->entry->id->attributes("im",TRUE)->id;

Check out this comment for one more demo.

Upvotes: 5

Devang Rathod
Devang Rathod

Reputation: 6726

Not sure but maybe something like this

$attr = $xml->id[0]->attributes();
echo $attr['im:id'];

Upvotes: 0

Related Questions