Name : perl-XML-Parser-Nodes
| |
Version : 0.08
| Vendor : obs://build_opensuse_org/devel:languages:perl
|
Release : lp154.1.1
| Date : 2023-01-27 17:00:37
|
Group : Development/Libraries/Perl
| Source RPM : perl-XML-Parser-Nodes-0.08-lp154.1.1.src.rpm
|
Size : 0.02 MB
| |
Packager : https://www_suse_com/
| |
Summary : Extends XML::Parser
|
Description :
When XML::Parser::parse is used without callback functions, the returned object can get pretty hairy for complex objects. XML::Parser::Nodes provides methods to access that object\'s internals as a sequence of nodes.
XML::Parser::Nodes also has a constructor to create an object directly from a complex Perl object, similar to XML::Dumper->pl2xml(). The following two statements are equivalent:
$xmlnode = XML::Parser::Nodes->pl2xml( $ComplexPerlObject ) ;
$xmlnode = XML::Parser::Nodes->parse( XML::Dumper->pl2xml( $ComplexPerlObject ) ) ;
As a basic background, an XML document can be thought of as nested name-value- pairs. Basically, a node value is either a string or a set of child nodes. It\'s easy to imagine an XML object as a complex Perl object with a hierarchy of HASH references, whose bottom element is a scalar:
print $company->{$division}->{$location}->{$department}->{Director}->{FirstName} ;
Might refer to a string \"Jim\".
In an XML document represented by an XML::Parser::Nodes object, that value would be accessed as:
print $xmlnode->childnode( $company )->childnode( $division )->childnode( $location )->childnode( $department )->childnode(\'Director\' )->childnode(\'FirstName\')->gettext() ;
Alternatively,
$nodekey = join \'/\', $division, $location, $department, \'Director\', \'FirstName\' ; print $xmlnode->nodebykey( $nodekey )->gettext ;
Some XML documents are more complex and contain sets of values.
print $company->{$division}->{$location}->{$department}->{Staff}->[0]->{FirstName} ;
Represents a complex object where department staff consists of a set of individuals, one of whom has the first name, \"Jim\".
One of the features of XML::Parser::Nodes is the ability to survey the contents of a node. The most basic is \'childlist()\' which returns an ordered list of element names. If the node consists of 5 children with the same name, that name will be returned 5 times.
The \'tree()\' function is similar, except it recurses into each child. The returned values are similar to file pathnames where a slash represents a parent->child relationship.
There are analogous methods to retrieve a node: \'childnode()\' takes an element name as an argument; \'nodebykey()\' takes the path representation as its argument. When the key refers to a direct child, these two methods are interchangeable. These methods each return an array, but can be called in a scalar context, which returns the first matching node. In order to use the recursive methods and techniques, the caller should be confident that the target is a unique location.
\'cells()\' could be applied to each child of the division staff node in the example above and the results used in a spreadsheet application or database table.
This module is primarily designed to retrieve data from a complex XML document. The \'dump()\' method restores the XML document. This method is useful for converting a branch of an large XML object into a smaller document. The \'wrapper()\' method creates a wrapper node for this purpose.
\'childnodes()\' returns the child nodes as elements. An element is an array pair consisting of the element name and node value. Custom functions will most likely accept these elements as arguments. \'dump()\' is a wrapper for the method \'xmlout()\', which takes this element pair as its arguments. With no arguments, \'childnode()\' functions identically.
XML::Parser::Nodes can be used to create custom XML output.
|
RPM found in directory: /packages/linux-pbone/ftp5.gwdg.de/pub/opensuse/repositories/devel:/languages:/perl:/CPAN-X/15.4/noarch |