PDA

View Full Version : [SOLVED] Parsing XML Help



john3j
05-08-2015, 11:55 AM
I have the following XML code:

<?xml version="1.0" ?>
<NessusClientData_v2>
<Policy><policyName>Full Scan</policyName>
<Preferences><ServerPreferences><preference><name>plugin_set</name>
<value>16775;16066;...</value>
</preference>
<preference><name>TARGET</name>
<value>192.168.0.1</value>
</preference>
</ServerPreferences>
<Preferences>
</NessusClientData_V2>


I am trying to utilize the following code to show "192.168.0.1" in a message box, but I am apparently doing something wrong. Here is my code:

Sub ParseXML(fname, IP)
Set oXMLFile = CreateObject("Microsoft.XMLDOM")
oXMLFile.Load (fname)
Set MyNode = oXMLFile.SelectSingleNode("/NessusClientData_v2/Preferences/ServerPreferences/Preference[../name='TARGET']/text")
If Not MyNode Is Nothing Then
MsgBox MyNode.Text
End If
If anyone could help me figure out what I am doing wrong, I would appreciate it. I am using Microsoft Excel 2010. I am not getting an error or a message box of any kind.

p45cal
05-08-2015, 05:26 PM
I don't know the best way to do this but this seems to work:

Set myNode = oXMLFile.SelectSingleNode("NessusClientData_v2/Policy/Preferences/ServerPreferences/preference/name[../name = 'TARGET']")
If Not myNode Is Nothing Then
' MsgBox myNode.ParentNode.ChildNodes(1).Text
MsgBox myNode.NextSibling.Text
End If

john3j
05-11-2015, 04:23 AM
p45cal,

As always, that worked great! I appreciate your time trying to help me figure this out. You are a genius!