Jump to content

Parse XML and write value to INI file


Go to solution Solved by blckpythn,

Recommended Posts

I was recently tasked with pulling some data from older XML files we inherited to populate our database with. In particular I wish to be able to parse the XML below in Autoit, get the value for "DataUploadCompleted", write that value to an INI file which can then be processed by our Systems Management tool and inserted into it's database. I cannot parse XML directly with the Systems Management tool so was hoping Autoit would be a quick solution.

Anyone able to give me some ideas on the best way to go about this... In the past the XML files I have parsed were all rather easy to locate the Xpath for and pull data from, but I can't figure out the best way to do so with the format of this one... Here's the XML code:

<?xml version="1.0"?>
<Variables Version="0">
    <Variable Name="DataUploadDays" Value="Sun,Mon,Tue,Wed,Thu,Fri,Sat"/>
    <Variable Name="DataUploadStart" Value="20"/>
    <Variable Name="DataUploadEnd" Value="21"/>
    <Variable Name="DataUploadRandom" Value="1/1/2011 0:00:00 AM"/>
    <Variable Name="DataUploadRandomSuccessWindow" Value="1,0"/>
    <Variable Name="DataUploadRandomFailedWindow" Value="1,0"/>
    <Variable Name="DataUploadStarted" Value="1/1/2011 0:00:00 AM"/>
    <Variable Name="DataUploadCompleted" Value="1/1/2011 0:00:00 AM"/>
    <Variable Name="DataUploadStatus" Value="Pending" Result="" DateTime="1/1/2011 0:00:00 AM"/>
    <Variable Name="DataDownloadDays" Value="Sun,Mon,Tue,Wed,Thu,Fri,Sat"/>
    <Variable Name="DataDownloadStart" Value="04"/>
    <Variable Name="DataDownloadEnd" Value="05"/>
    <Variable Name="DataDownloadRandom" Value="1/1/2011 0:00:00 AM"/>
    <Variable Name="DataDownloadRandomSuccessWindow" Value="1,0"/>
    <Variable Name="DataDownloadRandomFailedWindow" Value="1,0"/>
    <Variable Name="DataDownloadStarted" Value="1/1/2011 0:00:00 AM"/>
    <Variable Name="DataDownloadCompleted" Value="1/1/2011 0:00:00 AM"/>
    <Variable Name="DataDownloadStatus" Value="Pending" Result="" DateTime="1/1/2011 0:00:00 AM"/>
</Variables>
Link to comment
Share on other sites

  • Solution

Something I know how to do! Try the following. You need the >_XMLDomWrapper.au3

#include <_XMLDomWrapper.au3>
_XMLFileOpen(@DesktopDir & "\test.xml")
$value = _XMLGetAttrib('//Variables/Variable[@Name="DataUploadCompleted"]', 'Value')
IniWrite("c:\pathtoini\myinifile.ini", "Sectionname", "datauploadkeyname", $value)

Or shortened to

#include <_XMLDomWrapper.au3>
_XMLFileOpen(@DesktopDir & "\test.xml")
IniWrite("c:\pathtoini\myinifile.ini", "Sectionname", "datauploadkeyname", _XMLGetAttrib('//Variables/Variable[@Name="DataUploadCompleted"]', 'Value'))
Edited by blckpythn
Link to comment
Share on other sites

Thanks a ton blckpythn! I have been trying to get it to run all day, and even with your help I was still getting an error while compiling (incorrect syntax, and unexpected number of arguments). I finally decided to try it on my own computer instead of my work laptop and it compiled and works just fine. 

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