| Basicos::XML - Herramientas auxiliares para manipulación de XML |
Basicos::XML - Herramientas auxiliares para manipulación de XML
use Basicos::XML;
use XML::Parser;
my $xml = Basicos::XML->new();
eval {
my $parser = XML::Parser->new(
Style => 'Stream',
Pkg => 'MyParser' );
$parser->parse( \*STDIN );
};
if (not $@) {
my %xml_values = $xml->as_hash();
...
}
package MyParser;
sub StarTag {
my ($expat, $name ) = shift;
$xml->start_tag( $name );
}
sub EndTag {
my ($expat, $name ) = shift;
$xml->end_tag( $name );
}
sub Text {
my $expat = shift;
my $data = $_;
$xml->set_value( $data ) if $data;
}
=head1 DESCRIPTION
Este módulo crea una clase para integrarla cómodamente en un analizador XML tipo the XML::Parser manpage, tal y como se muestra en la sinopsis.
my $obj = Basicos::XML->new();
Crea un nuevo objeto de tipo Basicos::XML y lo inicializa. Aunque puede aceptar parámetros es preferible no hacerlo, porque están diseñados para ser utilizados internamente.
$obj->reset();
Inicializa un objeto Basicos::XML y desecha todo el contenido anterior.
$obj->start_tag( $tagname )
Abre una etiqueta en el objeto y crea una nueva rama en el árbol que mantiene internamente.
$obj->end_tag( $tagname )
Cierra una etiqueta y retrocede un nivel en el árbol interno.
$obj->set_value( $value )
Añade un valor a la última rama abierta, de manera que para almacenar un contenido de tipo
<nombre>Pepe</nombre>
se debe emplear la siguiente secuencia de métodos:
$obj->start_tag( 'nombre' )->set_value( 'Pepe' )->end_tag( 'nombre' );
no es lo más óptimo, pero es así como funciona un parser XML de tipo flujo
(stream); quizás en el futuro se incluya otro método que haga lo mismo en
una única llamada..
my @etiquetas = $obj->current();
my $ultima = $obj->current();
Permite obtener una lista de etiquetas abiertas hasta el momento ó sólo la última, dependiendo del entorno de llamada.
my %xml_values = $obj->as_hash();
Retorna el hash con todos los valores recopilados hasta el momento.
my $texto_xml = $obj->as_xml( $noempty );
Construye un texto en formato XML con el contenido actual del objeto, con la posibilidad de ignorar aquellas ramas que no contengan ningún valor.
A list of every error and warning message that the module can generate.
A full explanation of any configuration system(s) used by the module,
including the names and locations of any configuration files, and the
meaning of any environment variables or properties that can be set. These
descriptions must also include details of any configuration language used.
A list of all the other modules that this module relies upon, including any restrictions on versions, and an indication of whether these required modules are part of the standard Perl distribution, part of the module's distribution, or must be installed separately.
A list of any modules that this module cannot be used in conjunction with. This may be due to name conflicts in the interface, or competition for system or program resources, or due to internal limitations of Perl (for example, many modules that use source code filters are mutually incompatible).
There are no known bugs in this module. Please report problems to <Maintainer name(s)> (<contact address>). Patches are welcome.
Víctor Moral <victor@taquiones.net>, Angel Ortega <angel@triptico.com>
Copyright (c) 2005 <Venexma Europa, S.L.>. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
| Basicos::XML - Herramientas auxiliares para manipulación de XML |