Jump to content

Help with XML reading


Deoctor

Recommended Posts

Hai

i need to fetch the following data from the xml which i have attached as text file

channel->title

channel->item->text

 

i have written the code in the following way but it is not working

can any one help me out :P

<?php
$url='http://chaitu09986025424.blog.co.in/feed/rss/';
$xml = file_get_contents($url);
$fh = fopen("test.xml", 'w');
fwrite($fh, $xml);
$objDOM = new DOMDocument();
  $objDOM->load("test.xml"); //make sure path is correct


  $channel = $objDOM->getElementsByTagName("channel");
  // for each note tag, parse the document and get values for
  // tasks and details tag.

  foreach( $channel as $value )
  {
    $titles = $value->getElementsByTagName("title");
    $title  = $titles->item(0)->nodeValue;


    $details = $value->getElementsByTagName("description");
    $detail  = $details->item(0)->nodeValue;

    echo "$task <br> $detail <br>";
    $item=$objDOM->getElementsByTagName("item");
        foreach($item as $value1)
        {
            $titles_item=$value1->getElementsByTagName("title");
            $tit_item=$titles_item->item(0)->nodevalue;
            
            echo "hee<br>".$tit_item;
        }
  }

?>

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/184400-help-with-xml-reading/
Share on other sites

This will fetch title and description from xml file.

<?php
$xml = new SimpleXMLElement('http://chaitu09986025424.blog.co.in/feed/rss/', 0, true);

$data = array();
foreach($xml->channel->item as $item) {
$i = count($data);
$data[$i]['title'] = (string)$item->title;
$data[$i]['description'] = (string)$item->description;
}

var_dump($data);

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.