I recently upgraded my development PC and some of the XML functionality stopped working properly. I was using MSXML2 on the old PC. That wasn't available on the new PC, just MSXML3 and MSXML6, so I decided to move to the version 6. Here is a snippet of some code from an XML class I wrote:
Code:
Dim xDoc As MSXML2.DOMDocument60
Dim root As MSXML2.IXMLDOMNode
Dim m_node As MSXML2.IXMLDOMNode
Public Function LoadXmlFile(fileName As String) As Boolean
LoadXmlFile = False
On Error Resume Next
Set xDoc = New DOMDocument60 ' MSXML2.DOMDocument
If Err.Number = 0 Then
xDoc.async = False
xDoc.validateOnParse = False
xDoc.Load (fileName)
If Err.Number <> 0 Then
m_error = Err.Description
Set xDoc = Nothing
Set root = Nothing
Else
m_error = ""
Set root = xDoc.DocumentElement
LoadXmlFile = True
End If
End If
On Error GoTo 0
End Function
Public Function GetNodeByName(Name As String) As Boolean
GetNodeByName = False
If Not xDoc Is Nothing Then
On Error Resume Next
Set m_node = xDoc.SelectSingleNode("//" & Name)
GetNodeByName = Not m_node Is Nothing
m_error = IIf(Err.Number = 0, "", Err.Description)
On Error GoTo 0
End If
End Function
Here is some of my calling code:
Code:
Const xml_file As String = "C:\ProgramData\EDESuite\Year{year}\EDExpress for Windows\EDESuite.xml"
Dim oXml As New clsXML
Dim fso As New FileSystemObject
Dim valName As String
Dim xmlFile As String
Dim isOK As Boolean
valName = ""
xmlFile = Replace$(xml_file, "{year}", awdYear)
isOK = fso.FileExists(xmlFile)
If isOK Then
isOK = oXml.LoadXmlFile(xmlFile)
If isOK Then isOK = oXml.GetNodeByName("Database")
If isOK Then
valName = oXml.GetNodeAttributeValue("Path")
isOK = valName <> "~"
End If
Else
MsgBox "EDESuite.xml file not found." & vbCrLf & "Please contact Tech Support", vbExclamation, "Error"
End If
So this statement: isOK = oXml.LoadXmlFile(xmlFile)
works, and the XML file loads fine. Here is the xml from the file after executing the above statement
Code:
<?xml version="1.0"?><EDESuite xmlns="http://tempuri.org/EDESuiteAppSettings.xsd">
<Database Path="M:\FedConnect\Schools\UAV\Expres19.accdb"></Database>
<Executable Path="C:\Program Files (x86)\EDESuite\EDExpress for Windows 2018-2019"></Executable>
<InstalledModules>
<Module Name="ApplicationProcessing" Load="true"></Module>
<Module Load="false" Name="COD"></Module>
<Module Load="false" Name="DirectLoan"></Module>
<Module Name="FinancialAidShoppingSheet" Load="true"></Module>
<Module Name="Global" Load="true"></Module>
<Module Name="Packaging" Load="true"></Module>
<Module Load="false" Name="Pell"></Module>
<Module Load="false" Name="TEACH"></Module>
</InstalledModules>
</EDESuite>
The problem occurs with the statement: If isOK Then isOK = oXml.GetNodeByName("Database")
When I step through the GetNodeByName method, the statement: Set m_node = xDoc.SelectSingleNode("//" & Name)
returns Nothing for m_node.
This has always worked in he past, but now it doesn't. The x-path seems to be right. Is there some difference with MSXML6 that I am missing?
Thanks...