XML::SimpleObject::LibXML 0.60 review

Download
by rbytes.net on

XML::SimpleObject::LibXML is a Perl extension allowing a simple(r) object representation of an XML::LibXML DOM object. SYNOPSIS

License: Perl Artistic License
File size: 7K
Developer: Dan Brian
0 stars award from rbytes.net

XML::SimpleObject::LibXML is a Perl extension allowing a simple(r) object representation of an XML::LibXML DOM object.

SYNOPSIS

use XML::SimpleObject::LibXML;

# Construct with the key/value pairs as argument; this will create its
# own XML::LibXML object.
my $xmlobj = new XML::SimpleObject::LibXML(XML => $XML);
my $xmlobj = new XML::SimpleObject::LibXML(file => "./listing.xml");
my $xmlobj = new XML::SimpleObject::LibXML(); # empty DOM

# ... or construct with the parsed tree as the only argument, having to
# create the XML::LibXML object separately.
my $parser = new XML::LibXML;
my $dom = $parser->parse_file($file);
my $xmlobj = new XML::SimpleObject::LibXML ($dom);

my $filesobj = $xmlobj->child("files")->child("file");

# read values
$filesobj->name;
$filesobj->value;
$filesobj->attribute("type");

%attributes = $filesobj->attributes;
@children = $filesobj->children;
@some_children = $filesobj->children("some");
@children_names = $filesobj->children_names;

# set values
$filesobj->name("Files"); # set name
$filesobj->value("test"); # set text value
$filesobj->attribute("type", "bin"); # set existing attribute's value

# add/delete nodes
$filesobj->add_child
("owner" => "me"); # add new element
$filesobj->add_attribute
("size" => "4"); # add new attribute
$filesobj->delete; # unbinds node from parent

# document processing
$xmlobj->replace_names_values(xpath => "/files/file[0]/title",
value => "places.txt", name => "newtitle");
$xmlobj->delete_nodes(xpath => "/files/file/size");

# output
$xmlobj->output_xml;
$xmlobj->output_xml_file("./newfile.xml");

This is a short and simple class allowing simple object access to a parsed XML::LibXML tree, with methods for fetching children and attributes in as clean a manner as possible. My apologies for further polluting the XML:: space; this is a small and quick module, with easy and compact usage. Some will rightfully question placing another interface over the DOM methods provided by XML::LibXML, but my experience is that people appreciate the total simplicity provided by this module, despite its limitations. These limitations include a minor loss of speed compared to the DOM, loss of control over node types, and protection (aka lack of knowledge) about the DOM. I encourage those who want more control and understanding over the DOM to study XML::LibXML; this module's source can be instructive, too.

Requirements:
Perl

XML::SimpleObject::LibXML 0.60 keywords