thraxil has asked for the wisdom of the Perl Monks concerning the following question:
what i'm trying to do is take a little snippet of text, and insert it into an XML parse tree. the trick is that i want to insert it as XML, not as plain text.
eg, say i have the following XMLish text:
<p>this is a paragraph with some <abbrev>XML</abbrev> in it</p>i want to be able to stick that into an arbitrary point in another XML document that i've already got parsed into a DOM tree. i don't need to do anything with the tree after i've inserted the text except write it out to a file so it doesn't bother me to have the newly inserted text not parsed into nodes. currently, i'm using XML::DOM but i'm not too attached to it. i've tried creating a new node in the document and using $newnode->setNodeValue($text), then inserting that node into the proper spot in the tree. this sort of works, except it tries to be a little too helpful and escapes the text, turning it into:
<p>this is a paragraph with some <abbrev>XML</abbrev> in it</p>not quite what i want. i've also tried parsing the text into its own tree and just inserting the root node from that tree into the other document's tree but it complains that the node comes from a different document and won't let me do it. the only things i can think of to do now are: 1) do it that way, then run a regexp over the XML file after it's been toString'd unescaping the text (very ugly and not very robust), or 2) parsing the text into its own tree and recursively copying node values from one tree to the other. there has to be a better way.
so can anyone think of a way to either tell XML::DOM not to escape the text, or to otherwise insert a chunk of XML into a tree without nasty recursive traversals?
anders pearson // digital samurai personal // http://www.columbia.edu/~anders/ weblog // http://thraxil.dhs.org/
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: inserting text into an XML tree
by mirod (Canon) on May 11, 2001 at 09:17 UTC | |
by thraxil (Prior) on May 11, 2001 at 23:20 UTC | |
|
Re: inserting text into an XML tree
by Banky (Acolyte) on May 11, 2001 at 08:40 UTC |