elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  PHP (Moderador: #!drvy)
| | | |-+  XML + PHP
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: XML + PHP  (Leído 1,467 veces)
Draco Heroicus


Desconectado Desconectado

Mensajes: 303


Ver Perfil
XML + PHP
« en: 9 Enero 2007, 23:07 pm »

Hola, si, ya lo investigue, hasta tengo un libro pero ya saben, uno es N00b y el libro tiene ejemplos odiosos  >:(

Me podrian ayudar?

Estoy haciendo un Menu CSS en una Web PHP usando XML, olviden lo del menu, como le hago para acceder a un XML, Cargar datos de el y Grabar en el.


En línea

alone-in-the-chat


Desconectado Desconectado

Mensajes: 587


Ver Perfil
Re: XML + PHP
« Respuesta #1 en: 9 Enero 2007, 23:41 pm »

Bueno ahorita toy en otra pero este te puede servir para parsear un xml
Código:
<?php

Class XmlParse
{

var $parser;
var $fileXml;
var $Element;
var $miArray;
var $arrayCont;
var $flag;
var $i;

function XmlParse($file)
{
    $this->fileXml = $file;
    $this->parser = xml_parser_create();
$this->Init();
}

function Init()
{
    xml_set_object($this->parser, $this);
    xml_set_element_handler($this->parser, 'handlerInicial', 'handlerFinal');
    xml_set_character_data_handler($this->parser, 'handlerDatos');
$this->miArray = array();
$this->arrayCont = array();
$this->flag = true;
}
function handlerInicial($parser, $nombre, $atributos)
{
if ($this->flag == true )
{
if (!array_key_exists($nombre,$this->miArray))
{
$this->miArray[$nombre] = array();
$this->arrayCont[$nombre] = 0;
}
}else{
$this->flag = true;
}
$this->Element = $nombre;
}
function handlerFinal($parser, $nombre)
{
$this->flag = false;
$this->arrayCont[$nombre]++;
}
function handlerDatos($parser, $dato)
{
if ($this->arrayCont[$this->Element] == "")
{
$this->arrayCont[$this->Element] = 0;
}
       $this->miArray[$this->Element][$this->arrayCont[$this->Element]] = $dato;
}
function miParser()
{
    if (!($fich = fopen($this->fileXml, 'r')))
{
        die('No pude abrir el fichero XML: '.$this->fileXml);
        return false;
    }
while ($data = fread($fich, 512))
{
   $resultado = xml_parse($this->parser, $data, feof($fich));
           if (!$resultado)
   {
               die(sprintf("Error de XML: %s en la linea %d",xml_error_string(xml_get_error_code($this->parser)),xml_get_current_line_number($this->parser) ) );
               xml_parser_free($this->parser);
           }
}
return $this->miArray;
}
}
?>

PD. ta un poco cutre la clase pero toy en otra sorry :D
solo sirve para parsear el xml te devolvera el contenido en un array ya tu ve si la puedes mejorar
Saludos.


Código:
<?php
include("ClsXmlParse.php");

$var = new XmlParse("sitemap.xml");
print_r($var->miParser());
?>
por si te gusta las cosas completas xDºº se usa asi
Saludos .
RePD.
Esto No deberia ir en el foro de PHP??? para eso se creo no??


« Última modificación: 10 Enero 2007, 02:51 am por alone-in-the-chat » En línea

Because maybe
You're gonna be the one that saves me
And after all
You're my wonderwall
d[n_n]b
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines