I want to navigate and get details of my xml document.
But it has a namespace. Due to this namespace in Multiblock
element, I am getting lists.length
as zero.(Please refer vba code below)
Please guide. Thanks in advance for reading. :) My xml document is:
<?xml version="1.0" encoding="UTF-16"?>
<MultiBlock xmlns="x-schema:ConfigFileSchema.xml">
<ErdbVersion>
<DbVersion>14.0</DbVersion>
<DbDesc>ERDB Release EXP431.1-49.0</DbDesc>
<DbGUID>56CFAF87-53A9-4042-8B4F-4CF94868416E</DbGUID>
<DbLangID>ENU</DbLangID>
</ErdbVersion>
<Block>
<BlockDef>
<BlockName>J60AOV1136</BlockName>
<EntityName>J60AOV1136</EntityName>
<BlockId>20031267</BlockId>
<BlockGUID>D11BF0DB-803D-49FC-A594-D234ABD1E156
</BlockGUID>
<BlockDesc>Exported on (MM-DD-YY HH:MM) 07-31- 2017
10:12</BlockDesc>
<TemplateName>SYSTEM:CONTROLMODULE</TemplateName>
<ClassName>CONTROLMODULE</ClassName>
<BaseTemplateName>SYSTEM:CONTROLMODULE
</BaseTemplateName>
<CreateType> </CreateType>
<Attribute>1610613248</Attribute>
<LifeCycleState>Loaded</LifeCycleState>
<AssignedTo>STFCEE8A_03</AssignedTo>
<Container></Container>
</BlockDef>
<Parameters>
<Parameter>
<ParamName>ALIASOPT</ParamName>
<ParamValue>OFF</ParamValue>
</Parameter>
<Parameter>
<ParamName>DISCOVORDER</ParamName>
<ParamValue>"TPN"</ParamValue>
</Parameter>
<Parameter>
<ParamName>METHODSCOPE</ParamName>
<ParamValue>"ALL"</ParamValue>
</Parameter>
</Parameters
</Block
</MultiBlock>
When I am trying to get Node details without xmlns="x-schema:ConfigFileSchema.xml"
I am able to navigate through nodes and get the values.
But with the same document and xmlns
attribute, i am having problem in navigating.
Here is my VBA code:
Sub AOVXML()
Dim XDoc As MSXML2.DOMDocument
Dim firstNamefield As MSXML2.IXMLDOMNodeList
Dim lists As MSXML2.IXMLDOMNodeList
Dim i, j As Integer
'Dim lists As MSXML2.IXMLDOMNode
Set XDoc = CreateObject("MSXML2.DOMDocument")
XDoc.async = False: XDoc.validateOnParse = False
XDoc.Load (ThisWorkbook.Path & "\J60AOV1136.cnf.xml")
'Reading the List Node
Set lists = XDoc.SelectNodes("//MultiBlock/Block")
MsgBox "Length of Lists nodes : " & lists.Length & vbCrLf & _
"First XML List Node : "
'Getting First Child node under Lists
Set firstNamefield = lists(0).ChildNodes
MsgBox firstNamefield.Length
'Looping through all XML nodes under List node
For i = 0 To firstNamefield.Length - 1
MsgBox firstNamefield(i).XML
Next i
Set XDoc = Nothing
End Sub