[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: Storing data
From:       Andreas Pakulat <apaku () gmx ! de>
Date:       2011-06-24 14:26:05
Message-ID: 20110624142605.GA28051 () neo ! apaku ! dnsalias ! org
[Download RAW message or body]

On 24.06.11 15:52:10, Thomas Lübking wrote:
> Am Friday 24 June 2011 schrieb Parker Coates:
> > For reading and writing "data storage" XML, I personally think the
> > QXmlStream(Reader|Writer) classes are nicer (and potentially more
> > performant because the whole document doesn't ever have to be stored
> > in memory). There was also some talk of removing QDomDocument in Qt5.
> 
> "eewww" ;-)
> 
> While it's certainly more performant and the "proper" (better) way to deal 
> with large documents, the caller has to care about validity himself, yesno?

To a certain extent, yes. In particular its possible to forget the
closing EndDocument which causes an invalid document or to write out
stuff not allowed before the document-element. However once you've got
the opening of a document-element, all following calls to writeXXX
functions will not break the validity of the XML. writeAttribute for
example merely writes out 'foo=bar' which is valid anywhere in XML,
except before/after the root element.

> So to just map some data into a valid xml, my impression was that QDomDoc is 
> the errrrr... more "reliable" approach. *shrug*

No its not, you can shoot yourself into your own foot in the same way as
above with QDomDocument:
    QDomDocument doc;
    QDomText a = doc.createTextNode("foo");
    doc.appendChild( a );
    doc.appendChild( doc.createElement("foo"));

That'll generate "foo<foo />" from doc.toByteArray() which is not valid XML.

So there are pitfalls in either case if you forget to create a document
element. The only thing thats 1 tad bit better with QDomDocument is that
there's no need for an explicit closing of the document.

Andreas

 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic