2

I'm trying to parse XML feed with SimpleXML, here is a chunk of the XML tree:

<item>
<game:name>Tetris</game:name> 
<game:desc>Way Cool Game</game:desc>
<size>5mb</size> 
</item>

Well actually, I can succesfully access 'size' with something like that: $item->size, but how do I get value? Of course I can't call like that: $item->game:name, and I don't know how what goes after ':' is called. Is it a parameter, attribute or what?

Thanks for advance!

Andersson83
  • 441
  • 1
  • 8
  • 12

3 Answers3

2

Use the children() function to get the children of the namespace.

$useThis = $xmlDoc->children("http://game.namespace/");

given that http://game.namespace is the URL to your game namespace in the root node.

Here's an explanation/sample:

M8R-1jmw5r
  • 4,896
  • 2
  • 18
  • 26
Jess
  • 42,368
  • 6
  • 37
  • 51
1

You need to define the namespace for game. XML requires all namespaces to be defined. There have been several previous answers about using custom namespaces: i.e.

Community
  • 1
  • 1
txwikinger
  • 3,006
  • 1
  • 25
  • 33
0

As for the getting the value of a SimpleXMLElement, you just cast it to a string:

$size_value = (string)$item->size;
Henrik Opel
  • 19,341
  • 1
  • 48
  • 64