views:

60

answers:

3
oXML = Server.CreateObject("Msxml2.DOMDocument.4.0")

oNode = oXML.createElement("CommonCustomerSearch")

can someone explain what the lines of code above are doing? i'm more interested in the first line as the method it is written in exits when it hits that line, so apparently the variable oXML isn't being set. i know that oXML is supposed to be set to some kind of COM object but can you explain the "Msxml2.DOMDocument.4.0" part a bit more? what is that, where is that, and what will it look like in .NET (this code is a classic asp)? i don't know what the second line of code above is either but the method never even reaches it so if you have any ideas about what that is doing would be great too. thanks

+2  A: 

That is code using the old MSXML COM object. The XML namespace in .NET will do almost the exact same thing, using similar syntax. And bypass COM (a good thing). Convert these statements to use .Net's XML.

Msxml2.DOMDocument.4.0 is the COM object name.

If the createobject is existing the method, then something is probably wrong.

In .net you can say, like, Dim MyXMLDocument as New XML.XMLDocument, etc.

FastAl
+1  A: 

That classic ASP code is making use of the XML DOM library. The first line (if properly coded with the set keyword) creates an XML document in memory. The second line creates an XML node named CommonCustomerSearch.

.NET Framework 3.5+

If you want to move to .NET 3.5 or later, you could do the same thing with System.Linq.Xml

var xmlDoc = new XDocument(new XElement("CommonCustomerSearch"));

You can read the Getting Started Guide for LINQ to XML for more info.

.NET Framework 2.0

It sounds like you're limited to .NET 2.0, so you can use System.Xml to accomplish this in a less sexy way.

XmlDocument doc = new XmlDocument();
doc.LoadXml("<CommonCustomerSearch/>");
jessegavin
yea, i would like to try this but System.Linq.Xml is .NET 4. i'm developing on .NET 2.
can you recommend a 2.0 version of your example? the commenter above you mentioned XML.XMLDocument to create an XML doc, but how would i create the node?
System.Linq.Xml is available in 3.5 actually. I will edit my answer to show you how to do this in 2.0
jessegavin
+1  A: 

The Msxml2.DOMDocument.4.0 is a COM object and the line is supposed to create an instance of the class. I don´t know if this is all the code but you are required to use the Set keyword when initializing an instance of an object. So it should in fact be

Set oXML = Server.CreateObject("Msxml2.DOMDocument.4.0")
Set oNode = oXML.createElement("CommonCustomerSearch")

The Msxml class is an abstraction of an xml document.

bjorsig