#!/usr/bin/perl -w

use strict;
use XML::Simple;
use Data::Dumper;
 
my $data = XMLin(‘nokaut.xml’);
 
print Dumper($data);


$url = ‘data.txt’;

$xml = @file_get_contents($url);
$xml_obj = simplexml_load_string($xml);     

foreach($xml_obj->page as $page) {
    echo $page->title.’: ‘;
    echo $page->url.’<br>’;

}

Pprzykłądowy XML:
<?xml version=”1.0″ encoding=”UTF-8″?>
<pages>
    <page>
    <id>1</id>
    <title><![CDATA[miejsce mapa Sopot]]></title>
    <url><![CDATA[ http://mapy.emiejsca.pl/sopot_sopot_sopot_pomorskie,mapa.html ]]></url>
    <thumb><![CDATA[ http://mapy.emiejsca.pl/sopot_sopot_sopot_pomorskie,miejsca.html ]]></thumb>
    </page>
    <page>
    <id>2</id>
    <title><![CDATA[miejsce mapa Gdynia]]></title>
    <url><![CDATA[ http://mapy.emiejsca.pl/gdynia_gdynia_gdynia_pomorskie,mapa.html]]></url>
    <thumb><![CDATA[ http://mapy.emiejsca.pl/gdansk_gdansk_gdansk_pomorskie,miejsca.html]]></thumb>
    </page>
</pages>


<?xml version=”1.0″ encoding=”UTF-8″?>
<root>
        <prognoza>
                <id>Egipt</id>
    <temp>
      <w>  7.0</w>
      <w>  8.0</w>
      <w>  9.0</w>
    </temp>
        </prognoza>
</root>

<?
$root = simplexml_load_file(‘test.xml’);
$wt = $root->prognoza->temp->w;

print_r($wt); echo ‘<br>’;

foreach($wt as $w){
    echo ‘temp:’ .$w. ‘<br/>’;
}
?>

Wynik:
SimpleXMLElement Object ( [0] => 7.0 )
temp: 7.0
temp: 8.0
temp: 9.0


<tresc>
<![CDATA[ Do czego w HTML może być wykorzystana konstrukcja:
<div class="underline"> ]]>
</tresc>


$res = file_get_contents($url);

$content_start  = strpos($res, ‘</form>’) + strlen(‘</form>’);

$head_end       = $content_start;
$content_end    = strpos($res, ‘</xml-export>’);
$foot_start     = strpos($res, ‘</xml-export>’);

$head    = substr($res, 0, $head_end);
$content = substr($res, $content_start, $content_end – $content_start);
$foot    = substr($res, $foot_start);

$content = nl2br(html_entity_decode($content));
$content = htmlspecialchars_decode($content);
$content = UTF8toISO2($content);

$html_doc = $content;