You are here: XML_PARSE_INTO_STRUCT « PHP Programming Language « IT news, forums, messages
XML_PARSE_INTO_STRUCT

Posted by Jack on 06/16/07 23:23

Hi,
I am trying to parse an xml file and I am having some problems. Here
is a sample structure of my xml file.

<title>Example</title>
<link rel="self" href="http://link0.com"/>

<entry>
<title>E1</title>
<link href="http://link1.com"/>
</entry>
<entry>
<title>E2</title>
<link href="http://link2.com"/>
</entry>

I want to be able to output the following

<p><a href="http://link0.com'">Example</a></p>
<p><a href="http://link1.com'">E1</a></p>
<p><a href="http://link2.com'">E2</a></p>

here is my code:
$file="test.xml";

$xml_parser = xml_parser_create();

$handle = fopen($file, "rb");
while (!feof($handle)) {
$data .= fread($handle, 8192);
}
fclose($handle);

xml_parse_into_struct($xml_parser, $data, $vals, $index);
xml_parser_free($xml_parser);

foreach ($vals as $xml_elem) {
if ($xml_elem['level'] == 1){
// THIS IS WHERE I SOMEHOW GOING TO READ AHEAD OR ACCESS THE NEXT
TAG=LINK AND SOMEHOW READ ITS ATTRIBUTE
if ($xml_elem['tag'] == 'TITLE')
printf ("<h1>%s</h1>\n", $xml_elem['value']);
else if ($xml_elem['tag'] == 'SUBTITLE')
printf ("<h3>%s</h3>\n", $xml_elem['value']);
}

The problem is write here because i don't know how I can first read
the LINK attribute first and then the title.

Thanks

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация