First, sorry by me english
I need get the variable names to extract tags ans attributes values to output the HTML
this is the test.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Canal de noticias</title>
<description>Novedades, información y últimas actualizaciones</description>
<link>http://lwww.emprear.com.local</link>
<language>es-AR</language>
<webMaster>webmaster@emprear.com</webMaster>
<copyright>© Copyright 2005, GG. Todos los derechos reservados</copyright>
<managingEditor>GCG</managingEditor>
<pubDate>Dom, 02 Oct 2005 15:28:58 -03:00</pubDate>
<image>
<url>http://emprear.com/rss/3232_rss.png</url>
<title>página principal</title>
<link>http://emprear.com</link>
</image>
<item>
<title>Actualización total del Sitio</title>
<description>
Artículo uno.....
</description>
<link>http://emprear.com.local/a1</link>
<author>Webmaster</author>
<dc:creator>creador</dc:creator>
<pubDate>Vie, 17 Mar 2006 04:03:48 GMT</pubDate>
<guid>http://emprear.com.local/?00011</guid>
<category>general</category>
</item>
<item>
<title>Artículo 2</title>
<description>solo se admite la etiqueta <![CDATA[<a href="#">link nulo</a> ]]>
en tanto esté dentro de un bloque CDATA.<![CDATA[ <br>
Adviertan que en XML de entrada el GUID de este ITEM tiene como atributo
isPermaLink="false".<br>
Dicho valor no es reistrado por el array <b>$canal</b> ]]>
</description>
<link>http://emprear.com.local/a2</link>
<author>Webmaster</author>
<dc:creator>crador </dc:creator>
<pubDate>Vie, 17 Mar 2006 04:03:48 GMT</pubDate>
<guid isPermaLink="false">25551343641</guid>
<category>general</category>
</item>
</channel>
</rss>
now, this is the script
<?php
header("Content-Type: Text/html;charset=iso-8859-1");
ini_set("default_charset","iso-8859-1");
$filename = "test.xml";
$obj->tree = '$obj->xml';
$obj->xml = "";
function startElement($parser, $name, $attrs) {
global $obj, $cade;
$cade='$test=isset($obj->tree->$name);';
if (!empty($test)){
$cade='$tmp=$obj->tree->$name;';
eval("$cade");
$cade='$arr=is_array($obj->tree->$name);';
eval("$cade");
if (!$arr){
$cade='unset($obj->tree->$name);';
eval("$cade");
$cade='$obj->tree->$name[0]=$tmp;';
eval("$cade");
$cnt = 1;
}else{
eval('$cnt=count('.$obj->tree.'->'.$name.');');
}
$obj->tree .= '->'.$name."[$cnt]";
}else {
$obj->tree .= '->'.$name;
} //fin noempty
if (count($attrs)){
eval($obj->tree.'->attr=$attrs;');
}
} // fin funcion startElement
function endElement($parser, $name) {
global $obj;
//
for($a=strlen($obj->tree);$a>0;$a--) {
if (substr($obj->tree, $a, 2) == '->') {
$obj->tree = substr($obj->tree, 0, $a);
break;
}
}
}
function characterData($parser, $data) {
global $obj;
## el eval que sigue tira errores , pero el funcionamiento de la script no se altera
@eval($obj->tree.'->data=\''.$data.'\';');
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($filename, "r"))) {
die("no se puede abrir entrada xml");
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s en linea %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
print "<pre>";
print_r($obj->xml);
print "</pre>";
?>
--------------------------------------------------------------------
the result of print_r($obj->xml); is the next estructure
stdClass Object
(
[RSS] => stdClass Object
(
[attr] => Array
(
[VERSION] => 2.0
[XMLNS:DC] => http://purl.org/dc/elements/1.1/
)
[data] =>
[CHANNEL] => stdClass Object
(
[data] =>
[TITLE] => stdClass Object
(
[data] => Canal de noticias
)
[DESCRIPTION] => stdClass Object
(
[data] => Novedades, información y últimas actualizaciones
)
[LINK] => stdClass Object
(
[data] => http://lwww.emprear.com.local
)
[LANGUAGE] => stdClass Object
(
[data] => es-AR
)
[WEBMASTER] => stdClass Object
(
[data] => webmaster@emprear.com
)
[COPYRIGHT] => stdClass Object
(
[data] => © Copyright 2005, GG. Todos los derechos reservados
)
[MANAGINGEDITOR] => stdClass Object
(
[data] => GCG
)
[PUBDATE] => stdClass Object
(
[data] => Dom, 02 Oct 2005 15:28:58 -03:00
)
[IMAGE] => stdClass Object
(
[data] =>
[URL] => stdClass Object
(
[data] => http://emprear.com/rss/3232_rss.png
)
[TITLE] => stdClass Object
(
[data] => página principal
)
[LINK] => stdClass Object
(
[data] => http://emprear.com
)
)
[ITEM] => stdClass Object
(
[data] =>
[TITLE] => stdClass Object
(
[data] => Artículo 2
)
[DESCRIPTION] => stdClass Object
(
[data] =>
)
[LINK] => stdClass Object
(
[data] => http://emprear.com.local/a2
)
[AUTHOR] => stdClass Object
(
[data] => Webmaster
)
[PUBDATE] => stdClass Object
(
[data] => Vie, 17 Mar 2006 04:03:48 GMT
)
[GUID] => stdClass Object
(
[data] => 25551343641
[attr] => Array
(
[ISPERMALINK] => false
)
)
[CATEGORY] => stdClass Object
(
[data] => general
)
)
)
)
)
-----------------------------------
my question is : wich are the variable names of each element [TAGS and ATTRIBUTES !!!!,,some of there into arrays()] to make the HTML output
thanks
emprear