becu Posted June 24, 2007 Share Posted June 24, 2007 Let say I have this xml file: <Url> http://www.pagesoftheheart.net/gallery/data/500/3660Love_each_other.jpg </Url> <Thumbnail> <Url>http://mud.mm-a2.yimg.com/image/2218795354</Url> <Thumbnail> all I need is get and display the info inside <Url> element inside Thumbnail. What should I do? because the code I wrote, everytime, I encounter an opening tag <URL>, it will put the data in between the tags into the variable. thanks. Link to comment https://forums.phpfreaks.com/topic/56970-xml-parser-help/ Share on other sites More sharing options...
trq Posted June 24, 2007 Share Posted June 24, 2007 What should I do? because the code I wrote, everytime, I encounter an opening tag <URL>, it will put the data in between the tags into the variable Can we see this code? Link to comment https://forums.phpfreaks.com/topic/56970-xml-parser-help/#findComment-281420 Share on other sites More sharing options...
becu Posted June 24, 2007 Author Share Posted June 24, 2007 <?php $file = "http://search.yahooapis.com/ImageSearchService/V1/imageSearch?appid=.hLnSDPV34ETvZalCRwGE5j7.4C8rh7u0bHBMN_wsC3LZAJC8pXBLn2ZnjvWDzaF0w--&query=love&results=50&start=1"; $insideitem = false; $url = ""; $thumb = ""; $col = 0; function startElement($parser, $name, $attrs) { global $insideitem, $url, $thumb, $col; if ($name == "URL") $insideitem = true; else $insideitem = false; } function characterData($parser, $data) { global $insideitem, $tag, $url, $thumb, $col; if ($insideitem) { $m = $col % 2; switch ($m) { case "0": $url = $data; break; case "1": $thumb = $data; break; } } } function endElement($parser, $name) { global $insideitem, $url, $thumb, $col; if ($name == "URL") { $re = $col % 2; if ($re == "0") { printf("{$open}<td onMouseOver=this.style.backgroundColor='{$bg}'; onMouseOut=this.style.backgroundColor=''><div align=\"center\"><a href='%s'><img src='%s' width='120'></a></div></td>{$close}", $url, $thumb); } } $col++; } ?> As you can see above, I try to get rid of one of the url, but the result turns out an image of one thumbnail having the url of the next image. And I bet this is not the best possible solution. There gotta be a way to get just the URL inside THUMBNAIL. thanks. Link to comment https://forums.phpfreaks.com/topic/56970-xml-parser-help/#findComment-281422 Share on other sites More sharing options...
becu Posted June 25, 2007 Author Share Posted June 25, 2007 anybody knows? Link to comment https://forums.phpfreaks.com/topic/56970-xml-parser-help/#findComment-281635 Share on other sites More sharing options...
teng84 Posted June 25, 2007 Share Posted June 25, 2007 dou want to get the address? then use the file_get_content or tell me if i was wrong Link to comment https://forums.phpfreaks.com/topic/56970-xml-parser-help/#findComment-281639 Share on other sites More sharing options...
becu Posted June 25, 2007 Author Share Posted June 25, 2007 dou want to get the address? then use the file_get_content or tell me if i was wrong I don't think that's what i'm asking. thanks anyway. Link to comment https://forums.phpfreaks.com/topic/56970-xml-parser-help/#findComment-281645 Share on other sites More sharing options...
teng84 Posted June 25, 2007 Share Posted June 25, 2007 ok so you want to get the url instead of image? Link to comment https://forums.phpfreaks.com/topic/56970-xml-parser-help/#findComment-281646 Share on other sites More sharing options...
becu Posted June 25, 2007 Author Share Posted June 25, 2007 my code, every time it sees an opening "<Url>" tag, it will get the data in between those tags. In this case, there are 2 <Url> tags in one xml file and I only need to get data in between <Url> </Url> tags in <Thumbnail>. Is there a way to know that we're in the <Url> tag of Thumbnail not the other <Url> tag Link to comment https://forums.phpfreaks.com/topic/56970-xml-parser-help/#findComment-281654 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.