Microsoft.XMLDOM Performance

I have an ASP page in web application which loads some xml (from a string from another source) and then parses it in various ways to render data on the page.  This does not use XSL for various reasons.

I am using Set objXML = Server.CreateObject("Microsoft.XMLDOM")

I amaware that there are many Microsoft Com objects for doing the same task and wondered which one I should use for performance, multiple hits on the page etc.  If you could also tell me why a certain one is better to use that would be great too.

Thanks

Dave
LVL 19
daveamourAsked:
Who is Participating?
 
rdcproConnect With a Mentor Commented:
Oh, and if you do anything with W3C XML Schema, you pretty much have to stick with the newer MSXML 4.0. which is the first progID I posted:

Set objXML = Server.CreateObject("Msxml2.DomDocument.4.0")

0
 
rdcproCommented:
I would certainly not use that one for Server side work!  It's ancient.

Use:

Set objXML = Server.CreateObject("Msxml2.DomDocument.4.0")

or a little slower, a little older, but still supports the old 1998 XSL Patterns syntax:

Set objXML = Server.CreateObject("Msxml2.DomDocument")

I would also avoid using strings.  Use IStream.  Much safer (no encoding problems) and it's faster and uses fewer server resources.



Regards,
Mike Sharp

0
 
daveamourAuthor Commented:
Ok thanks

What is IStream though?

My actual xml is coming from an existing VBScript Function which grabs data from another server and returns it as a string.

Thanks

Dave
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
rdcproCommented:
An example of using IStream would be, instead of:

strXml = objXML.xml
Response.write(strXml)

you would use:

objXML.save(Response)

And instead of

objXML.loadXML(strInputXML)

you would use:

objXML.load(xmlHTTP.responseBody)

The load and save methods use a stream interface.  It depends on how your VBScript function works, but there's probably a more efficient way than serializing to a string, then loading the string into the DomDocument object.

Is this VBScript function by any chance using the ServerXMLHTTPRequest object?

Regards,
Mike Sharp
0
 
daveamourAuthor Commented:
Ok thanks

My VBScript is using MSXML2.ServerXMLHTTP and is wrapped in a Function which returns svrXmlHttp.ResponseText

Is this good or bad?

Dave
0
 
rdcproCommented:
Instead of

        objXML.loadXML svrXmlHttp.ResponseText

you can either directly assign the DOM object, like:

        objXML = srvXmlHttp.ResponseXML

In fact, unless you're going to do something else with the XML so that you need a separate DomDocument object, you can treat ResponseXML as a DomDocument object itself.  For example, to transform using XSLT, and send the results to the client:

srvXmlHttp.ResponseXML.tranformNodeToObject(objXsl, Response)

Direct assignment is pretty efficient, but some servers seem to mess up the response in some way or another so that ResponseXML doesn't actually return a DomDocument Object.  I've never exactly figured out why, but I believe it's because the content-type is incorrectly set on the remote server.  Usually this works well, and if it works with a particular server, it should always work with it.  That is, it's not an intermittant type of failure.  Either a request to a server parses correctly into a DomDocument object, or it doesn't.  If it fails, you can always parse the stream or body as in the next examples.

You can load using IStream:

        objXML.load srvXmlHttp.ResponseStream

or you can load as an unsigned array of bytes:

        objXML.load srvXmlHttp.ResponseBody

Any of these is probably safer than using ResponseText, unless you're absolutely sure of the character encoding.


Regards,
Mike Sharp
0
 
daveamourAuthor Commented:
Ok thanks Mike, I'll go and have a play with these ideas.

Cheers

Dave
0
All Courses

From novice to tech pro — start learning today.