Friday, January 22, 2010

Conditionally query specific elements within an XML document


     the name
     the desc
     misc garbage

Suppose you had 100 of these and wanted to obtain just the name and description for a specific id

$doc = simplexml_load_string();

$results = $doc->xpath("//tree[contains(id,'1')]/child::*[self::name or self::desc]"); 


That will get the job done

No comments:

Post a Comment