Consulting

Results 1 to 3 of 3

Thread: Parsing XML Help

  1. #1
    VBAX Contributor
    Joined
    Mar 2009
    Location
    Indiana
    Posts
    113
    Location

    Parsing XML Help

    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.

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    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
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Contributor
    Joined
    Mar 2009
    Location
    Indiana
    Posts
    113
    Location
    p45cal,

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •