http://qs1969.pair.com?node_id=709747

H4 has asked for the wisdom of the Perl Monks concerning the following question:

I want to process tree-structured data which is not XML but can easily be converted into XML. I want to make this conversion on the fly, creating XML nodes and adding them to the in-memory structure. Then, I want to use XPath expressions to access several nodes, modify them, and write the whole thing out into an XML file.

I read several XML::* manpages, and even the 'Perl&XML' book, but cannot find a place to start with. I was imagining something like my $tree = XML::some_class->new; my $new_node = $tree->new_node('node_tag', 'node_text'); $known_node->add_child($new_node), and then feeding $tree into an XML::XPath instance. Or, I might consider generating SAX events while reading my data source which would magically create the data structure in memory.

In fact, I already wrote code which creates a tree-like structure in memory, so it would be easy to turn it into a data structure which XML::XPath understands, but I cannot find the spec of what is required on XPath's side.

Almost everything I've found so far concentrates on parsing XML files, or on writing handlers for SAX events. What I found on SAX drivers was not too instructive either. A code sample would be great, but a link to further reading will do.