3

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user2194875
  • 31
  • 1
  • 2

2 Answers2

5

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.

Passerby
  • 9,715
  • 2
  • 33
  • 50
0

Not sure but maybe something like this

$attr = $xml->id[0]->attributes();
echo $attr['im:id'];
Devang Rathod
  • 6,650
  • 2
  • 23
  • 32