Welcome Guest, Not a member yet? Register   Sign In
Help to parsing an XML element
#1

[eluser]nickifrandsen[/eluser]
Hey there

I'm working on parsing this bit of xml and can't seem to get it right. Hope that one of you can provide a little tip. That would save my day Wink

Code:
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:exInfo="http://www.gametrailers.com/rssexplained.php" version="2.0">
    <channel>
        &lt;title&gt;Gametrailers.com - Customized RSS Feed&lt;/title&gt;
        <description>Gametrailers presents your customized RSS feed</description>
        &lt;link&gt;http://www.gametrailers.com/&lt;/link&gt;
        <image>
            <url>http://www.gametrailers.com/images/sig.gif</url>
            &lt;title&gt;GameTrailers&lt;/title&gt;
            &lt;link&gt;http://www.gametrailers.com/&lt;/link&gt;
        </image>
        <language>en-us</language>
        <copyright>Copyright 2005 Gametrailers.com, all rights reserved.</copyright>
        <generator>Gametrailers.com</generator>
        <lastBuildDate>Fri, 26 Mar 2010 4:47:02 EDT</lastBuildDate>
        <webMaster>[email protected] (Brent Phillips)</webMaster>
        <item>
....
            <exInfo:platform>xb360</exInfo:platform>
            <exInfo:fileType>
                <type>flv</type>
                <fileSize>25046937</fileSize>
                &lt;link&gt;http://www.gametrailers.com/player/63085.html?r=1&amp;type=flv&lt;/link&gt;
                &lt;embedcode&gt;
                    &lt;![CDATA[
                        &lt;object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="gtembed" width="480" height="409"&gt;
                        <param name="allowScriptAccess" value="sameDomain" /> <param name="movie" value="http://www.gametrailers.com/remote_wrap.php?mid=63085"/> <param name="quality" value="high" />
                        &lt;embed src="http://www.gametrailers.com/remote_wrap.php?mid=63085" swLiveConnect="true" name="gtembed" align="middle" allowScriptAccess="sameDomain" quality="high"
                        pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="480" height="409"&gt;&lt;/embed> &lt;/object&gt;
                    ]]>
                &lt;/embedcode&gt;
            </exInfo:fileType>

Code:
&lt;?php foreach($xml->channel->item as $row) : ?&gt;
    &lt;?php echo form_open(); ?&gt;
        &lt;?php $exInfo = $row->children('http://www.gametrailers.com/rssexplained.php'); ?&gt;
            &lt;?php echo form_input('game_name' , $exInfo->gameName); ?&gt;
            &lt;?php echo form_input('movie_title' , $exInfo->movieTitle); ?&gt;
            &lt;?php echo form_input('game_id' , $exInfo->gameID); ?&gt;
            &lt;?php echo form_input('gt_url' , $exInfo->gameURL); ?&gt;
            &lt;?php echo form_input('pub_date' , $row->pubDate); ?&gt;
            &lt;?php echo form_input('platform' , $exInfo->platform); ?&gt;
            &lt;?php echo form_input('thumbnail' , $exInfo->image); ?&gt;
            &lt;?php echo form_textarea('trailer' , $exInfo->fileType->embedcode); ?&gt;
            &lt;?php echo form_textarea('description' , $row->description); ?&gt;
        <br><br>
    &lt;?php endforeach; ?&gt;
.........

Thank you very much for your time!
#2

[eluser]nickifrandsen[/eluser]
Please any little help would be appreciated. I'm really stuck on this!

thanks
#3

[eluser]antonumia[/eluser]
why don't you use xpath?

There's a testbed to help you get started.
#4

[eluser]antonumia[/eluser]
something like this should get you started. NB:I've not tested it:

Code:
// in your constructor
private $_xmlData;
//

function loadXML($filename=''){
        if ($filename=='')
           {  
           return 0;
           }
        $this->_xmlData = new DOMDocument();
        $this->_xmlData->load($filename);
        return $this->_xmlData;
    }

function parseXML(){
    $xmlfile = $this->xml->loadXML('/path/to/your.xml');    
    $xp = new domxpath($xmlfile);
        // get every item node in the file
        $result = $xp->query("//item");
        
        foreach ($result as $node){
                 ...use xpath to find the node data you want inside each <item> node and add it to your form -  send an array to another function...?
                }
        //do stuff with your form
}
#5

[eluser]umefarooq[/eluser]
try this xml library will help you

http://codeigniter.com/wiki/Xml_Library/
#6

[eluser]nickifrandsen[/eluser]
Thank you both. I think that made things a little clearer Smile




Theme © iAndrew 2016 - Forum software by © MyBB