Jump to content

php, xml and SimpleXML


mcleary

Recommended Posts

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

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.

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>';

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.