Lightweight xml tree builder
use XML::Parser::Lite::Tree; my $tree_parser = XML::Parser::Lite::Tree::instance(); my $tree = $tree_parser->parse($xml_data); OR my $tree = XML::Parser::Lite::Tree::instance()->parse($xml_data);
This is a singleton class for parsing \s-1XML\s0 into a tree structure. How does this differ from other \s-1XML\s0 tree generators? By using XML::Parser::Lite, which is a pure perl \s-1XML\s0 parser. Using this module you can tree-ify simple \s-1XML\s0 without having to compile any C.
For example, the following \s-1XML:\s0
<foo woo="yay"><bar a="b" c="d" />hoopla</foo>
Parses into the following tree:
'children' => [ { 'children' => [ { 'children' => [], 'attributes' => { 'a' => 'b', 'c' => 'd' }, 'type' => 'element', 'name' => 'bar' }, { 'content' => 'hoopla', 'type' => 'text' } ], 'attributes' => { 'woo' => 'yay' }, 'type' => 'element', 'name' => 'foo' } ], 'type' => 'root' };
Each node contains a \*(C`type\*(C' key, one of \*(C`root\*(C', \*(C`element\*(C' and \*(C`text\*(C'. \*(C`root\*(C' is the document root, and only contains an array ref \*(C`children\*(C'. \*(C`element\*(C' represents a normal tag, and contains an array ref \*(C`children\*(C', a hash ref \*(C`attributes\*(C' and a string \*(C`name\*(C'. \*(C`text\*(C' nodes contain only a \*(C`content\*(C' string.
Returns an instance of the tree parser. Creates a new parser. Valid options include \*(C`process_ns\*(C' to process namespaces. Parses the xml in $xml and returns the tree as a hash ref.
Copyright (C) 2004-2008, Cal Henderson, <[email protected]>
XML::Parser::Lite.