mcleary Posted February 13, 2009 Share Posted February 13, 2009 I'm having trouble extracting what I need out of my xml. I need to use the following url to get it and print it as xhtml. Does anyone see what the problem is with this? $result1 = $xml->xpath("///data[group=$parm]"); echo "<h4>$result1->asXML()</h4>"; <==printing 0 here I know it's getting the parm's ok with: http://lyle.smu.edu/~mcleary/a2/Assignment2b.php?data=youtube&parm=UB40 My xml is http://lyle.smu.edu/~mcleary/a2/Assignment1C.xml I thought I had it right with //data in the above expression, but it didn't print the expected UB40. My original idea was to iterate foreach user, but I think I can use xpath like I have above instead. Once I find UB40 my plan is to just echo $result1->youtube; Any ideas why it's not finding UB40? Link to comment https://forums.phpfreaks.com/topic/145099-php-xml-and-simplexml/ Share on other sites More sharing options...
allworknoplay Posted February 13, 2009 Share Posted February 13, 2009 I don't understand, I see your output and I see UB40... Link to comment https://forums.phpfreaks.com/topic/145099-php-xml-and-simplexml/#findComment-761471 Share on other sites More sharing options...
mcleary Posted February 13, 2009 Author Share Posted February 13, 2009 The UB40 you are seeing is from printing the parameter into the script. I need it to show the result of printing result1. Right now, it's showing ->asXML(). I have echo "<h4>$result1[0]->asXML()</h4>"; that gives this. Before I tried echo "<h4>$result1->asXML()()</h4>"; which gave me a 0. I think it's not returning anything from the xpath results but I'm not sure why. Link to comment https://forums.phpfreaks.com/topic/145099-php-xml-and-simplexml/#findComment-761521 Share on other sites More sharing options...
allworknoplay Posted February 13, 2009 Share Posted February 13, 2009 ok, are you using too many slashes? $result1 = $xml->xpath("///data[group=$parm]"); echo "<h4>$result1->asXML()</h4>"; <==printing 0 here Should be maybe? $result1 = $xml->xpath("//data[group=$parm]"); echo '<ul>'; foreach ($result1 as $foobar) { echo "<li>$foobar</li>"; } echo '</ul>'; Link to comment https://forums.phpfreaks.com/topic/145099-php-xml-and-simplexml/#findComment-761535 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.