I have an XML file and this XML file has namespaces declared
<CrystalReport xmlns="urn:crystal-reports:schemas:report-detail" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:crystal-reports:schemas:report-detail http://www.businessobjects.com/products/xml/CR2008Schema.xsd">
This is causing problems in my VBA code in Excel. When I remove the namespaces of this line above, it works fine.
My question is: How can I ignore this namespace without have to open the xml file and remove manually?
The code I am using:
Public xmlDOM As MSXML2.DOMDocument60
Public Sub setXML(xmlFileName As String)
'Set xmlDOM = CreateObject("MSXML2.DOMDocument")
Set xmlDOM = New MSXML2.DOMDocument60
xmlDOM.async = False
xmlDOM.Load xmlFileName
End Sub
Public Function getNode(p_strNode As Variant) As Variant
Dim objNodes As IXMLDOMNodeList
Dim objNode As IXMLDOMNode
Dim storage As Variant
Dim X As Integer
Set objNodes = xmlDOM.SelectNodes(p_strNode)
Set getNode = objNodes
End Function
Public Sub SB_StartLoadClarityReport()
Dim d_path As String
Dim d_node As Variant
Dim d_arrayFields As Variant
d_path = F_GetPathXML()
'@Temp
d_path = Cells(1, 1).Value
'Open XML File
setXML (d_path)
'Get the project fields
Set d_node = getNode("CrystalReport/Details/Section")
d_arrayFields = F_GetProjectFields(d_node)
End Sub
Private Function F_GetProjectFields(p_strNode As Variant)
'Get the project fields
'Ex: <Field Name="PROJECTNAME1" - Get PROJECTNAME1
Dim d_arrayFields As Variant
Dim p_item As IXMLDOMElement
Dim d_count As Integer
d_count = 1
For Each p_item In p_strNode.Item(0).ChildNodes
If d_count = 1 Then
ReDim d_arrayFields(1 To d_count)
Else
ReDim Preserve d_arrayFields(1 To d_count)
End If
d_arrayFields(d_count) = p_item.Attributes.Item(0).Text
d_count = d_count + 1
Next p_item
F_GetProjectFields = d_arrayFields
End Function