-2

I am porting a VB6 project to C#. I have the following VB6 code that I don't fully understand:

 Dim xmlDoc As Object
 Set xmlDoc = CreateObject("MSXML2.DomDocument." & sVer)
 xmlDoc.setProperty "NewParser", True

I have never done VB coding before. Can someone explain what the above lines do and what would the equivalent code be in a language like Java or C#. Thanks!

jac
  • 9,666
  • 2
  • 34
  • 63
Kaushik Balasubramanain
  • 1,248
  • 6
  • 28
  • 42

2 Answers2

1

A quick run down on what this does:

Set xmlDoc = CreateObject("MSXML2.DomDocument." & sVer)

This line instantiates a specific version of Microsoft's implementation of W3C's DOM standard. You shouldn't have to specify version - you should just have to do:

Set xmlDoc = CreateObject("MSXML2.DomDocument")

Or even better, add a reference to the latest "Microsoft XML n.n" library and do:

Dim xmlDoc As MsXml2.DomDocument
Set xmlDoc = New MsXml2.DomDocument

The reason why there are so many versions is because there are several, slightly incompatible versions of the same library. And different installed applications may each use a different version.

As for:

xmlDoc.setProperty "NewParser", True

This is an example of Microsoft's non-standard extensions to DOM. To support various Microsoft-specific behaviours, they have added the concept of "secondary properties", which have no basis in the official W3C DOM standard. In this specific case, it is setting the "NewParser" property to True (see http://msdn.microsoft.com/en-gb/library/windows/desktop/ms767616%28v=vs.85%29.aspx). This means nothing in any version other than MSXML6.DLL.

There is no direct Java version, but this example allows you to create DOM object based on a string:

How do I load an org.w3c.dom.Document from XML in a string?

In this example, the setProperty() call does not exist.

The .NET equivalent (in C#) is:

using System.xml

function doIt()
{
    XmlDocument doc = new XmlDocument();
}

SetProperty() doesn't exist in XmlDocument either.

Community
  • 1
  • 1
Mark Bertenshaw
  • 5,594
  • 2
  • 27
  • 40
0

Without knowing much of VB6 either, it sounds very much like XML parsing. Throwing MSXML2.DomDocument at google.com as suggested, gave this document from MSDN as #1 result which should lead you in the right direction.

Alexander Rühl
  • 6,769
  • 9
  • 53
  • 96