Link to home
Start Free TrialLog in
Avatar of Emergent ESI
Emergent ESIFlag for United States of America

asked on

Creating and loading and Server.CreateObject("Microsoft.XMLDOM") in C#

Hello Everyone,

Can someone please help me figure out what is the equivalent C# code for the following:

set xmldoc = Server.CreateObject("Microsoft.XMLDOM")

I am trying to receive an xsl as dom object and I thought this might work

XslCompiledTransform xslDoc = (XslCompiledTransform)Server.CreateObject("MSXML2.DOMDocument.3.0");

but I am not sure how to load the Request.  I want to use this as part of an ASP.Net page.  


Avatar of madhevan_pillai
Flag of India image

This may help you. This was from that site

A simpler solution to use the XML DOM object:

From Project/Add Reference/COM add a reference to Microsoft XML v4.0.

SXML2.DOMDocument40 doc = new DOMDocument40Class();
When using the doc object you will see listed all its methods:
doc.load, doc.loadXML, doc.transformNode
Avatar of Carl Tawn
How are you retrieving the transform, is it coming from disk or from a Http request? Either way, since its a .Net app you will want to avoid using COM objects. You can do everything you need with the built-on System.Xml namespace objects.
Avatar of Emergent ESI


carl_tawn:  I am getting the xslt from an http request.  

So I still need to load the Request Object.  Can you guys help me with that part please.


How do I get the Request object?

Sorry for the newbie questions.  Thanks again.
Well, as a very simplistic example, you want something along the lines of:
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("");
HttpWebResponse res = (HttpWebResponse)req.GetResponse();

// load the response into an XmlReader
XmlTextReader reader = new XmlTextReader(res.GetResponseStream());

// prepare the compiled transform
XslCompiledTransform transform = new XslCompiledTransform();

Open in new window

carl_tawn:  Thank you so much.  Just one more question.  If a client is sending me the xsl via a DOM document, how would I receive the Dom Object.  From you code, I gather that

the code makes the initial call to and would accept the response with HttpWebResponse.

I need to wait for a client to connect to my site.  When they connect, they will be sending me a xsl using DOM.  I am trying to figure out how to accept the object.  Thanks and I am sorry for the confusion.

Thanks again.
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks carl_tawn.  

I will be testing this and will get back to you.  I have another question.  

If I do the following:

      XmlTextReader reader = new XmlTextReader(Request.InputStream);

Do I still need to create the


or do I need the following?
    SXML2.DOMDocument40 doc = new DOMDocument40Class();

I think the XmlTextReader takes care of this but I wanted to check.

Also,  Do you have any suggesting on how to test this locally?  I will not be able to test this for real with the actual client until Monday.

Thanks again you are a life saver!.

No you don't need to. MSXML is the old COM based Xml object model. The .Net framework provides its own set of objects for dealing with Xml (XmlTextReader is one of them). This should be the preferred method of dealing with XML in your .Net apps otherwise you create a dependency on an external library, which you generally want to avoid if you can.
Does this still apply if the client is not a .Net client?  In other words, can I still just use XmlTextReader and not use Server.CreateObject("Microsoft.XMLDOM") .

Thanks again.

You should be able to. The client app should just be trying to send the raw xml rather than trying to actually send an xmldom object so all you will need to do is read that data.
Thank you soo much!
It worked.