OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [xml-dev] fastetst, string concatenation or DOM object?



Hi Peter,

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
string
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
s.Open
s.WriteText "<hello>world</hello>"
s.Position=0
doc.load s

(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.
--Jonathan

----- Original Message -----
From: "Peter Thornqvist" <thornqvist_peter@hotmail.com>
To: <xml-dev@lists.xml.org>
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.
>