> -----Original Message----- > From: Jenda Krynicky [mailto:[EMAIL PROTECTED] > Sent: Wednesday, October 03, 2007 6:12 AM > To: beginners@perl.org > Subject: Re: How to insert data onto an existing XML file > > On 2 Oct 2007 at 10:54, Matthew Whipple wrote: > > An ugly solution would be to chop off the end of whatever > file you're > > dealing with and then recreate it (assuming you know what the end of > > the file looks like). > > If you only have to bend backwards because the bright omnipotent > creators of the XML standard thought it would be fun to force you to > and the whole end-of-the-file that you need to chop off is a > "</roottag>" then it's actually the best solution. No matter what > would the XML purists love you believe. > > > A better solution would be to read the previous > > file and generate a new XML document. > > Which may be fine for small enough files, but is simply crazy for > anything longer. Parse and rewrite something to insert something in > the middle is something that can't be helped, but reparsing and > recreating everything for APPEND? > > The requirement of a root tag in XML is ... yet another lovely > misfeature of the format. > > Jenda
If XML is causing you problems, perhaps you should not be using it? In the end, you have to understand that XML is a hierarchical structure. You can't simply append data, it must be inserted at the correct level in the hierarchy. How difficult that is depends on the schema or DTD being used. It may be possible to simply chop off a couple of closing tags, insert your new data and restore the tags behind it. But again, the code needs to be smart enough to know which tags need to be where in order to insure the results are still well formed. If the file is too big, perhaps SAX is a better option that DOM. Bob McConnell -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/