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.


In reply to How to create XML tree from non-XML source by H4

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.