I've been messing around with XML::Twig the last couple days and have found it to be extremely useful for parsing huge xml documents, yet still keeping an easy interface to the data record. Bravo!
Since my code was mostly using Twig for XML input parsing, I decided that in my actual output XML generation, I'd give it a try as well. Not sure if it entirely makes much sense to do it like that, and perhaps it'll slow down performance... But I don't know, since I can't get it to work.
I've looked through all the online help documentation, and my guess stab at doing something like this would be like this:
my $out = new XML::Twig();
my $tag = "tag1";
my $text = "this is some text";
my $elt = XML::Twig::Elt->new($tag, $text);
...some how attach the element to the twig..
$out->flush;
I think I'm getting a little lost in the details. All the code I've seen for "pasting" elements apply to twigs that were generated using a parse on an existing document. I wanted to just completely create a new xml structure not at all similiar to the input XML. I'm probably trying to use the wrong tool for such a thing and should just use XML::Simple. I just like the thought of using the same package for everything. Any helpful example code?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.