Monday 15 February 2010

php - SimpleXML: Selecting Elements Which Have A Certain Attribute Value -



php - SimpleXML: Selecting Elements Which Have A Certain Attribute Value -

in xml document, have elements share same name, value of attribute defines type of info is, , want select of elements have value document. need utilize xpath (and if so, suggest right syntax) or there more elegant solution?

here's illustration xml:

<object> <data type="me">myname</data> <data type="you">yourname</data> <data type="me">myothername</data> </object>

and want select contents of <data> tags children of <object> who's type me.

ps - i'm trying interface netflix api using php - shouldn't matter question, if want suggest good/better way so, i'm ears.

try xpath:

/object/data[@type="me"]

so:

$mydataobjects = $simplexml->xpath('/object/data[@type="me"]');

and if object not root of document, utilize //object/data[@type="me"] instead.

php xml xpath simplexml netflix

No comments:

Post a Comment