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


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

here's example 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, use //object/data[@type="me"] instead.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -