Jump to content

Help using _XMLDomWrapper.au3 to read XML files


Recommended Posts

Hi much smarter than me people!

Someone pointed me to the _XMLDomWrapper.au3 to read XML files. I have figured out how to load the file using _XMLFileOpen but am stuck trying to parse the file to read individual data for each branch in the XML file. Here's my short section of code...it doesn't do much but open the file and then try to read one piece of data at this point. I'm also attaching the XML file that I'm trying to read. The XML file is created from an Adobe Acrobat 7.0 professional document. The value that I'm trying to load is the clients name that is a text field on the Adobe form. I'm getting the XML data file loaded ok (according to my debug msg box) but when I try to use "_XMLGetValue" to read the client name I'm getting a "-1" value and it's failing according to my debug msg box. I'm messing something up. Can anyone help?

#include <_XMLDomWrapper.au3>

Global $ClientName, $FileOpen

$FileOpen = _XMLFileOpen("C:\Program Files\AutoIt3\Todd's scripts\Contract Creator\testSOS_data.xml")

if $FileOpen Then

MsgBox(0, "Open File Correctly?", "Yes")

elseIf $FileOpen = -1 Then

MsgBox(48, "Open File Correctly?", "NO")

EndIf

$ClientName = _XMLGetValue("form1/Name")

if $ClientName = -1 Then

MsgBox(48, "Error", "Could Not Load Client Name")

else

MsgBox(0, "Client Name is", $ClientName)

EndIf

----------------------------------------------------

Thanks!

testSOS_data.xml

Link to comment
Share on other sites

try

#include <_XMLDomWrapper.au3>

Global $ClientName, $FileOpen

$FileOpen = _XMLFileOpen("testSOS_data.xml")

if $FileOpen Then
MsgBox(0, "Open File Correctly?", "Yes")
elseIf $FileOpen = -1 Then
MsgBox(48, "Open File Correctly?", "NO")
EndIf


$node = "/form1/Name";
;$ClientName = _XMLGetValue("form1/Name") ; old - wrong!! missing "/" form1
$ClientName = _GetFirstValue($node)

if $ClientName = -1 Then
MsgBox(48, "Error", "Could Not Load Client Name")
else
MsgBox(0, "Client Name is", $ClientName)
EndIf

; retruns array--- 
Func _GetFirstValue($node)
    $ret_val = _XMLGetValue($node)
    If IsArray($ret_val) Then
        Return ($ret_val[1])
    Else
        Return SetError(1,3,0)
    EndIf
EndFunc
Link to comment
Share on other sites

try

#include <_XMLDomWrapper.au3>

Global $ClientName, $FileOpen

$FileOpen = _XMLFileOpen("testSOS_data.xml")

if $FileOpen Then
MsgBox(0, "Open File Correctly?", "Yes")
elseIf $FileOpen = -1 Then
MsgBox(48, "Open File Correctly?", "NO")
EndIf


$node = "/form1/Name";
;$ClientName = _XMLGetValue("form1/Name") ; old - wrong!! missing "/" form1
$ClientName = _GetFirstValue($node)

if $ClientName = -1 Then
MsgBox(48, "Error", "Could Not Load Client Name")
else
MsgBox(0, "Client Name is", $ClientName)
EndIf

; retruns array--- 
Func _GetFirstValue($node)
    $ret_val = _XMLGetValue($node)
    If IsArray($ret_val) Then
        Return ($ret_val[1])
    Else
        Return SetError(1,3,0)
    EndIf
EndFunc

That works beautifully! thanks!

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...