Jump to content

SimpleXML help


devWhiz

Recommended Posts

Ok so I have a url that is an XML doc, it says at the top

 

"This XML file does not appear to have any style information associated with it. The document tree is shown below."

 

and it has info like this

 


<outer>
  <xml>
    <viewer>
      <user>
        <id>1245789</id>
        <name>CLueless</user>
        <business>none</business>
      </user>
    </viewer>
  </xml>
</outer>

 

How would I load the link and then assign everything to a variable like id, name and business

 

I usually use something like this but Im trying to get learn simple xml

 


$info = file_get_contents('url');
$id = explode('<id>', $info);
$id = explode('</', $id[1]);
$name = explode('<name>', $info);
$name = explode('</', $name[1]);
$biz = explode('<business>', $info);
$biz = explode('</', $biz);

Link to comment
Share on other sites

note you have a tag mismatch "<name>CLueless</user>"

<?php
  $xml_feed="<outer>
  <xml>
    <viewer>
      <user>
        <id>1245789</id>
        <name>CLueless</name>
        <business>none</business>
      </user>
    </viewer>
  </xml>
</outer>
";

if(!$xml = simplexml_load_string("$xml_feed")){
    echo "Can't connect to feed $xml_feed";
}else{
foreach ($xml->xml->viewer->user as $value){ 
$id=$value->id;
$name=$value->name;
$biz=$value->business;
echo"id=$id<br />\n";
echo"name=$name<br />\n";
echo"biz=$biz<br />\n";

}  
    
}
?>

 

Link to comment
Share on other sites


$xmll = file_get_contents('http://mob-dynamic-lb5.mobsters04.com/mob/refresh_stat_manual?user_id=496046235&session_id=');
$xml = simplexml_load_string($xmll);
foreach ($xml->xml->viewer->user as $value){ 
$id=$value->user_name;
$name=$value->user_id;
$biz=$value->error;
echo"id=$id<br />\n";
echo"name=$name<br />\n";
echo"biz=$biz<br />\n";
sleep(10000);
}  
    

what am I doing wrong

Link to comment
Share on other sites


$xmll = file_get_contents('http://mob-dynamic-lb5.mobsters04.com/mob/refresh_stat_manual?user_id=496046235&session_id=');
$xml = simplexml_load_string($xmll);
foreach ($xml->xml->viewer->user as $value){ 
$id=$value->id;
$name=$value->name;
$error=$value->error;
echo"id=$id<br />\n";
echo"name=$name<br />\n";
echo"error=$error<br />\n";
sleep(10000);
}  
    

what am I doing wrong

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.