🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.xml
Article #9765

Re: - Jak wyciagnac pojedyncze dane

#9765
From: SOLVER
Date: Thu, 20 Mar 2008 20:14
88 lines
3975 bytes
Na chwile obecna uzywam takiego parsera:

<?
// main function for parsing xml file
function MPxmlParse($file) {
    ini_xml(); //in globals variables
    $rXMLPARSER = xml_parser_create();
    xml_parser_set_option($rXMLPARSER, XML_OPTION_CASE_FOLDING, 1);
    xml_set_element_handler($rXMLPARSER, 'start_element',
'close_element');
    xml_set_character_data_handler($rXMLPARSER,'character_data');
    $fp = fopen($file, 'r');
    while($sXmlStream = fread($fp, 4096)) {
        if (!xml_parse($rXMLPARSER, $sXmlStream, feof($fp))) {
            die(sprintf("XML error: %s at line %d",
            xml_error_string(xml_get_error_code($rXMLPARSER)),
            xml_get_current_line_number($rXMLPARSER)));
        }
    }
    fclose($fp);
    $aRet['hotels'] = $GLOBALS[aXmlTotalElements];
    $aRet['infos']      = $GLOBALS[xmlInfos];
    return $aRet;
}

//start_element
function start_element($parser, $name, $attrs='') {
    $name =  strtolower(trim($name));
    $GLOBALS[sXmlactualElement] = $name;
    if(in_array($name, $GLOBALS[aSpecialElements])) {
        $GLOBALS[xmlElementCpt]++;
    }elseif($name == 'drt') {
        $GLOBALS[aXmlAttrs] = $attrs;
    }
}

///close_element
function close_element($parser, $name, $attrs='') {
    $name =  strtolower(trim($name));
    if($name == 'hotel' && $GLOBALS[sXmlactualElement] != 'file') {
        $GLOBALS[xmlElementCpt]++;
    }
}

//character_data
function character_data($parser, $data='') {
    if($GLOBALS[sXmlactualElement] != 'hotel'
    && $GLOBALS[sXmlactualElement] != 'drt'
    && !in_array($GLOBALS[sXmlactualElement],
$GLOBALS[aSpecialElements]) ) {
        $GLOBALS[aXmlTotalElements][$GLOBALS[xmlElementCpt]]
[$GLOBALS[sXmlactualElement]].= trim($data);
    }elseif($GLOBALS[sXmlactualElement] == 'drt') {
        $GLOBALS[xmlInfos] = $GLOBALS[aXmlAttrs];
    }else{
        if($GLOBALS[sXmlactualElement] != 'hotel') {
            $GLOBALS[xmlInfos][$GLOBALS[sXmlactualElement]].=
trim($data);
        }
    }
}

//initialize xml variables
function ini_xml() {
    $GLOBALS[aXmlTotalElements]     = array();
    $GLOBALS[sXmlactualElement]     = '';
    $GLOBALS[xmlElementCpt]         = 0;
    $GLOBALS[aXmlAttrs]             = array();
    $GLOBALS[xmlInfos]                = array();
    $GLOBALS[aSpecialElements] =
array('hotel','first_url','last_url','next_url','prev_url');
}
?>

a tak wyswietlam zawartosc:
include('include/functions/_xml_parser.php');
$sFile = 'http://xmlfile.xml';
$aArray = MPxmlParse($sFile); $aRess = $aArray['hotels'];
foreach ($aRess as $aInfo)
{
   echo$hotel_name=$aInfo['hotel_name'];
}

Czy da sie w jakis sposob zmodyfikowac skrypt abym mogl wyswietlic
potrzebne dane?

Pozdrawiam
Mariusz
Technical Details
Message-ID: <03404a99-5b86-4278-8f7b-9ee2e9d3bfe3@e6g2000prf.googlegroups.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!newsfeed.pionier.net.pl!news.glorb.com!postnews.google.com!e6g2000prf.googlegroups.com!not-for-mail
References: <15d5fb4c-e244-4a01-b0eb-2d2122b5c1a8@s12g2000prg.googlegroups.com> <frt4a4$q8i$1@atlantis.news.neostrada.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!newsfeed.pionier.net.pl!news.glorb.com!postnews.google.com!e6g2000prf.googlegroups.com!not-for-mail
From: SOLVER <mariusz@poplawski.org.uk>
Newsgroups: pl.comp.xml
Subject: Re: - Jak wyciagnac pojedyncze dane
Date: Thu, 20 Mar 2008 13:14:07 -0700 (PDT)
Organization: http://groups.google.com
Lines: 88
Message-ID: <03404a99-5b86-4278-8f7b-9ee2e9d3bfe3@e6g2000prf.googlegroups.com>
References: <15d5fb4c-e244-4a01-b0eb-2d2122b5c1a8@s12g2000prg.googlegroups.com>  <frt4a4$q8i$1@atlantis.news.neostrada.pl>
NNTP-Posting-Host: 82.44.85.102
Mime-Version: 1.0
X-Trace: posting.google.com 1206044047 24929 127.0.0.1 (20 Mar 2008 20:14:07 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 20 Mar 2008 20:14:07 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: e6g2000prf.googlegroups.com; posting-host=82.44.85.102;  posting-account=mkzgFAoAAADF5Cvl7dhuJ7K5mQCAOdTi
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.12)  Gecko/20080201 Firefox/2.0.0.12,gzip(gfe),gzip(gfe)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit