> Jenda Krynicky wrote: > > On 2 Oct 2007 at 10:54, Matthew Whipple wrote: > > > >> You can't really strictly "append" to a well-formed XML without > >> breaking the syntax. You need the properly closed top level element > >> at the very least, in addition to whatever nesting may be going on. > >> > > > > > >> 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. > > > > The requirement of a root tag in XML is ... yet another lovely > > misfeature of the format. > >
From: Matthew Whipple <[EMAIL PROTECTED]> > XML apparently just isn't for you. The closing root tag, if nothing > else, ensures that the document is whole and simplifies the parsing and > data format integrity which are large concerns of XML. Thanks for proving my point about the purists. If the designers of the XML had a bit less of the "we know what's best for you" mentality, they might allow us to specify whether we want to allow just one root tag (and thus let the parser test whether the file is complete) or not in the DTD or schema. So that the fact that our needs do not match their exact expectations, doesn't mean we have use something completely different. Besides you only get the the "document is complete" test done in time if you use DOM or something else that first parses the whole XML and only the lets you access the data. As soon as you move to SAX or something like that, you are on your own. You either have to test the file completeness yourself before you start the parser or you have to make sure you can rollback all changes done by the code that processed the part of the XML that was there already. Or parse the file twice, once to validate it and second time to process it. > If the structure > of the format seems counter-intuitive to what you're doing then use > something else and optionally export XML for features you may be > interested in. It doesn't fit everywhere. That's all nice except that 1) sometimes you do not get to choose and 2) sometimes your needs fit just great except ... except from some tiny little thing. From: "Bob McConnell" <[EMAIL PROTECTED]>: > 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. <foo><bar>x</bar><bar>y</bar></foo><foo><bar>XXX</bar></foo> is just as hierarchic as <root><foo><bar>x</bar><bar>y</bar></foo><foo><bar>XXX</bar></foo></ro ot> The only difference is that in the first case the root tag is not explicitely specified. And that if all you need to do is to add yet another <foo> tag at the end, you in the first case only have to append it while in the second you can either chop off the </root> (which is "unclean") or parse and rewrite everything. Sometimes the correct level in hierarchy is right at the root. Jenda ===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz ===== When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/