Solved

Microsoft.XMLDOM Performance

Posted on 2004-10-28
503 Views
Last Modified: 2008-02-01
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
Question by:daveamour
    7 Comments
     
    LVL 26

    Expert Comment

    by:rdcpro
    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
     
    LVL 26

    Accepted Solution

    by:
    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
     
    LVL 19

    Author Comment

    by:daveamour
    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
     
    LVL 26

    Expert Comment

    by:rdcpro
    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
     
    LVL 19

    Author Comment

    by:daveamour
    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
     
    LVL 26

    Expert Comment

    by:rdcpro
    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
     
    LVL 19

    Author Comment

    by:daveamour
    Ok thanks Mike, I'll go and have a play with these ideas.

    Cheers

    Dave
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
    Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    934 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now