[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [xml-dev] fastetst, string concatenation or DOM object?
- From: Jonathan Perret <email@example.com>
- To: firstname.lastname@example.org
- Date: Tue, 06 Nov 2001 18:08:26 +0100
Everybody will tell you that using the DOM is slower (and more verbose)
than string concats. This is mostly true, except that the worst case for
concatenation in VB is quite pathetic. Plus, you have to be extra careful to
generate well-formed XML, which mostly means escaping &,< and > (and
either ' or " in attribute values,depending on your choice of delimiters).
This can be done with the Replace$ function but you have to invoke it once
for each character you're escaping, which hurts when there's a lot of text.
The first problem (VB's slow concatenations) can be overcome by using
ADO 2.6's Stream object, with the added benefit that you can load a DOM
directly from it :
Dim s as New ADODB.Stream
Dim doc as New MSXML2.DOMDocument
(beware of ADO 2.5's Stream object, which won't work nicely with MSXML3).
If you're serious about generating XML in VB though, you'll want to look at
the MXXMLWriter class in MSXML3. You basically feed it SAX events
(startElement, characters, endElement...) and it generates well-formed XML
in a string or a Stream. Look up the article named
"Manually Building an XML Document with MXXMLWriter" in MSDN.
Hope this helps.
----- Original Message -----
From: "Peter Thornqvist" <email@example.com>
Sent: Tuesday, November 06, 2001 4:50 PM
Subject: [xml-dev] fastetst, string concatenation or DOM object?
> I would like to know which technic is the fastest, using string
> concatenation or the DOM (MSXML3) object to create a XML-string in VB6.