Jump to content

Issue getting XML values


Recommended Posts

Hi guys

I'm trying to read XML output that my AutoIt program receives, but my issue is that the kind of xml output isn't really the easiest kind to handle.

Example of what i receive:

<?xml version="1.0"?>
<Objects>
  <Object Type="System.Collections.Hashtable">
    <Property Name="Key" Type="System.String">State</Property>
    <Property Name="Value" Type="System.String">Completed</Property>
    <Property Name="Key" Type="System.String">Output</Property>
    <Property Name="Value" Type="System.String">Here some text blablablablablabla</Property>
  </Object>
</Objects>

What I need to do : 

Check the state which is actually the second property in this example, but the "key" is the property above and then do something with the output :-s

my idea of decent xml would be Objects > Object > State = "Completed"   and   Objects > Object > Output = "Blablablablablabla"

Does anyone have any idea how to do this? 

This is what I'm using : 

Local $XMLHandler = ObjCreate("Msxml2.DOMdocument.3.0")
    If Not IsObj ($XMLHandler) Then
        ; Some error shizzle
    Else
        $XMLHandler.loadXML ($theXMLoutput)
        ; ConsoleWrite ($XMLHandler.xml) shows the xml output i've given as an example
        $test = $XMLHandler.selectNodes("Something need to be here")
        ; Now I'd like to process it like this next line
        if $test.State = "completed" Then msgbox (0, "foobar", $test.Output)
    EndIf

I'm hoping someone will be able to help.

Edited by colombeen
Link to comment
Share on other sites

Not a fan of that XML...why would the key value pairs be sequential like that...they should be grouped into a parent node, or have the key and value attributes directly in one node.  Did you create the structure?

This is better:

<Objects>
  <Object Type="System.Collections.Hashtable">
    <Property Key="State">Completed</Property>
    <Property Key="Output">Here some text blablablablablabla</Property>
  </Object>
</Objects>

Otherwise, you have to just get all the child objects, and loop through them to get the key value pair...then, within the loop, add them into an array or something...but I highly recommend a new XML structure

$sXML ='<?xml version="1.0"?><Objects>  <Object Type="System.Collections.Hashtable">    <Property Name="Key" Type="System.String">State</Property>    <Property Name="Value" Type="System.String">Completed</Property>    <Property Name="Key" Type="System.String">Output</Property>    <Property Name="Value" Type="System.String">Here some text blablablablablabla</Property>  </Object></Objects>'

Local $oXML = ObjCreate("Microsoft.XMLDOM")
$oXML.loadxml($sXML)
$oPropertys = $oXML.selectNodes("//Object/Property")
For $oProperty In $oPropertys
    $sName  = $oProperty.getattribute("Name")
    $sValue = $oProperty.text
    ConsoleWrite($sName & "=" & $sValue & @CRLF)
Next

output:

Key=State
Value=Completed
Key=Output
Value=Here some text blablablablablabla

 

 

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...