XML::Tiny::Tree - Convert XML::Tiny output into a Tree
This is scripts/synopsis.pl:
#!/usr/bin/env perl use strict; use warnings; use XML::Tiny::Tree; # ------------------------------------------------ my($input_file) = shift || die "Usage $0 file. Try using data/test.xml as the input. \n"; my($tree) = XML::Tiny::Tree -> new ( input_file => $input_file, no_entity_parsing => 1, ) -> convert; print "Input file: $input_file. \n"; print "The whole tree: \n"; print map("$_\n", @{$tree -> tree2string}); print '-' x 50, "\n"; print "Bits and pieces from the first child (tag_4) of the second child (tag_3) of the root (tag_1): \n"; my(@children) = $tree -> children; @children = $children[1] -> children; my($tag) = $children[0] -> value; my($meta) = $children[0] -> meta; my($attr) = $$meta{attributes}; print "tag: $tag. \n"; print "content: $$meta{content}. \n"; print 'attributes: ', join(', ', map{"$_ => $$attr{$_}"} sort keys %$attr), ". \n";
XML::Tiny::Tree reads a file via XML::Tiny, and reformats the output into a tree managed by Tree.
new() is called as my($obj) = XML::Tiny::Tree -> new(k1 => v1, k2 => v2, ...).
new()
my($obj) = XML::Tiny::Tree -> new(k1 => v1, k2 => v2, ...)
It returns a new object of type XML::Tiny::Tree.
XML::Tiny::Tree
Key-value pairs accepted in the parameter list (see corresponding methods for details [e.g. "input_file([$string])"]):
Specify whether or not to get XML::Tiny to error if such declarations are found.
Default: 0.
This key is optional.
Specify the name of the XML file to process.
Default: ''.
This key is mandatory.
Specify whether or not to get XML::Tiny to do entity parsing.
If set to true, any unrecognised entities (ie, those outside the core five plus numeric entities) cause a fatal error.
This module is available as a Unix-style distro (*.tgz).
See http://savage.net.au/Perl-modules/html/installing-a-module.html for help on unpacking and installing distros.
Install XML::Tiny::Tree as you would for any Perl module:
Perl
Run:
cpanm XML::Tiny::Tree
or run:
sudo cpan XML::Tiny::Tree
or unpack the distro, and then either:
perl Build.PL ./Build ./Build test sudo ./Build install
or:
perl Makefile.PL make (or dmake) make test make install
Here, the [] indicate an optional parameter.
Triggers reading the XML file and conversion of the output of XML::Tiny into a Tree.
Returns an object of type Tree.
convert() takes the same parameters as "new([%arg])". See "Constructor and Initialization" for details.
convert()
Gets or sets the value of the option to pass to XML::Tiny.
fatal_declarations is a parameter to new([%arg]).
fatal_declarations
Gets or sets the name of the input file to pass to XML::Tiny's method parsefile().
parsefile()
input_file is a parameter to new([%arg]).
input_file
See "Constructor and Initialization" for details.
no_entity_parsing is a parameter to new([%arg]).
no_entity_parsing
strict_entity_parsing is a parameter to new([%arg]).
strict_entity_parsing
Each node in the tree is an object of type Tree, and has a method called value(). This method returns a string which is the name of the tag.
value()
See the "Synopsis" for sample code.
Each node in the tree is an object of type Tree, and has a method called meta(). This method returns a hashref containing 2 keys:
meta()
If the tag has no attributes, then $hashref is {}.
If the tag has no content, then $string is ''.
See the answer to the previous question.
Yes. See data/test.xml in the distro for such a case.
XML::Tiny.
XML::Tiny::DOM.
The file Changes was converted into Changelog.ini by Module::Metadata::Changes.
Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions.
https://github.com/ronsavage/XML-Tiny-Tree.
Email the author, or log a bug on RT:
https://rt.cpan.org/Public/Dist/Display.html?Name=XML-Tiny-Tree.
XML::Tiny::Tree was written by Ron Savage <ron@savage.net.au> in 2015.
Home page: http://savage.net.au/index.html.
Australian copyright (c) 2015, Ron Savage.
All Programs of mine are 'OSI Certified Open Source Software'; you can redistribute them and/or modify them under the terms of The Artistic License, a copy of which is available at: http://www.opensource.org/licenses/index.html
To install XML::Tiny::Tree, copy and paste the appropriate command in to your terminal.
cpanm
CPAN shell
perl -MCPAN -e shell install XML::Tiny::Tree
For more information on module installation, please visit the detailed CPAN module installation guide.