• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 569
  • Last Modified:

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
0
daveamour
Asked:
daveamour
  • 4
  • 3
1 Solution
 
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
 
rdcproCommented:
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
 
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now