Re: Recommended XML parser?
| From: | BB | Date: | Tue, 18 Jun 2002 11:28:38 +0000 |
| Subject: | Re: Recommended XML parser? | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-85291@lists.php.net to get a copy of this message | ||
I wrote something that did things to huge XML files (2meg+) and it took a
long time! (around 10 mins)
I used this code to read and process the XML into a arrays
function GetChildren($vals, &$i) {
$children = array();
if ($vals[$i]['value'])
array_push($children, $vals[$i]['value']);
while (++$i < count($vals)) {
switch ($vals[$i]['type']) {
case 'cdata':
array_push($children, $vals[$i]['value']);
break;
case 'complete':
$children[$vals[$i]['tag']] = $vals[$i]['value'];
break;
case 'open':
$children[] = GetChildren($vals,$i);
break;
case 'close':
return $children;
break;
}
}
}
function GetXMLTree($XML) {
$p = xml_parser_create("UTF-8");
xml_parser_set_option($p, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($p, $XML, $vals, $index) OR DIE("Invalid XML
file!");
xml_parser_free($p);
$i = 0;
return GetChildren($vals, $i);
}
Hope that helps :P
"Blake Barnett" <blake.barnett@developonline.com> wrote in message
news:1024359482.29230.29.camel@shiva.soulmachine.com...
> What is the recommended XML parser for use with PHP 4.2.1? (and also
> 4.1.0 if anyone is willing to answer that as well?)
>
> From reading the list archives I'm seeing a lot of people bash expat and
> lean toward libxml2, I just wanted to get the consensus before I commit
> a project to using one or the other.
>
> Thanks,
>
> --
> Blake Barnett (bdb) <blake.barnett@developonline.com>
> Sr. Unix Administrator
> DevelopOnline.com office: 480-377-6816
>
> Learning is a skill, you get better at it with practice.
>