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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -