开发者

How to parse this xml using PHP 4.4.8?

usually i have no problems parsing xml in PHP 5 by using Xml to array class. but now, i have a server with PHP 4.4.8 , and i really don't know how to parse it using built-in functions.

the xml is like that :

<?xml version="1.0" encoding="utf-8" ?>
<?pageview_candidate?>
 <SearchResponse Version="2.2">
  <web:Web>
   <web:Results>

     <web:WebResult>
       <web:Title>Apple Ipad</web:Title>
       <web:Description>The best way to experience the web</web:Description>
       <web:Url>http://www.apple.com/ipad/</web:Url>
     </web:WebResult>

     <web:WebResult>
       <web:Title>Apple Tablet Concept: the iPad Touch</web:Title>
       <web:Description>This can all be made better!</web:Description>
       <web:Url>http://factoryjoe.com/blog/148548/</web:Url>
     </web:WebResult>

   </web:Results>
  </web:Web>
 </SearchResponse>

I want to echo every search item, the title & description & url.

Note: the important is that the code should work in PHP Version 4.4.8

开发者_运维知识库

Thanks


The xml_parser* functions should still work in PHP4:-

$xml = "...."
$parser = xml_parser_create('UTF-8');
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $xml, $vals, $index);
xml_parser_free($parser);

Check out the manual for more in depth examples.

Edit:- Found a duplicate here: What to use for XML parsing / reading in PHP4


You could also use xslt_process and process it using an XSLT stylesheet. Take a look at some of the examples on that page. If you're unfamiliar with XSLT, here's a simple example with similar XML markup to yours.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜