Jump to content

Recommended Posts

Posted

So I would have to use some kind of regular expression to get just "TV1"? I want to add that text to a label...

XPath can be used to "qualify" your query results.

oÝ÷ ÙÈZw¥

There are ways to use regular expressions with xml but that is beyond the my scope of knowledge at the moment.

Posted

Thing you are looking for is Hash which is not natively implemented in AutoIt.

You mean 'standard' XML features; like : read XML into array isn't possible with this 'XML DOM wrapper' ?

Posted (edited)

You mean 'standard' XML features; like : read XML into array isn't possible with this 'XML DOM wrapper' ?

Have you looked at the UDF??

Arrays are returned from many functions

_XMLGetChildNodes get the names of the nodes.

_XMLGetValue get the values of the nodes.

The wrapper does not do maps or dictionaries or hashes. It is a simple query tool. If you want a multi-dimensional array, take the results returned from the wrapper and put it in a multi-dimensional array.

if you do that you can get the results you want:

Posted Image

edit: changed multidimensional to multi-dimensional

Edited by eltorro
Posted

To start : I'm a script/programming noob...

so :

Have you looked at the UDF??

I heve looked into the _XMLDomWrapper.au3 if that is what you mean...

(what is this 'UDF' thing anyway ?)

Arrays are returned from many functions

Idd; but why did someone suggest 'hash' for my question/example ? (I'm learning eh...)

The wrapper does not do maps or dictionaries or hashes. It is a simple query tool. If you want a multi-dimensional array, take the results returned from the wrapper and put it in a multi-dimensional array.

So the 'wrapper' is used to 'read' / 'get elements out of' .xml files right ? I wouldnt know what else you could do with it, I don't understand 'does not do maps or dictionaries or hashes'... (ps: I don't speak English...)

if you do that you can get the results you want:

I should do what ?

Could someone pls provide a very basic 'non theoretical' example using my xml data ?

I can't figure it out, also not by looking at other examples...

btw, right now, I reformat/lots_of_replaces the xml file to .ini files; which I can read/write in autoit ... though it's quite slow and not what it is intended for I think...

Prob, I just need to learn more basic autoit/scripting before diving into this; but I'll keep trying...

Posted

To start : I'm a script/programming noob...

so :

I heve looked into the _XMLDomWrapper.au3 if that is what you mean...

(what is this 'UDF' thing anyway ?)

Idd; but why did someone suggest 'hash' for my question/example ? (I'm learning eh...)

I think because you have put a 4 dimension array as how you want to arrange the data.

So the 'wrapper' is used to 'read' / 'get elements out of' .xml files right ? I wouldnt know what else you could do with it, I don't understand 'does not do maps or dictionaries or hashes'... (ps: I don't speak English...)

Yes, and write xml too.

Explanations:

Hash table Dictionary Dictionary

I should do what ?

Could someone pls provide a very basic 'non theoretical' example using my xml data ?

I can't figure it out, also not by looking at other examples...

btw, right now, I reformat/lots_of_replaces the xml file to .ini files; which I can read/write in autoit ... though it's quite slow and not what it is intended for I think...

Here is a very basic 'non theoretical' example using your data.

#Include <user/_XMLDomWrapper.au3>
#include <Array.au3>
_XMLFileOpen("youtube.xml")

;returns a array
$var =_XMLGetChildNodes('/ut_response/video_list')
ConsoleWrite($var)
_ArrayDump($var,"/ut_response/video_list")
Dim $nodes[1][3]
$dims =0
if $var <> -1 Then
    for $x = 1 to $var[0]
        if $var[$x]="video" Then
            ReDim $nodes[$dims+1][4]
             $childs = _XMLGetChildNodes("/ut_response/video_list/*["&$x&"]")
            $values = _XMLGetValue("/ut_response/video_list/*["&$x&"]/*")
            for $y = 1 to $childs[0]
            Switch $childs[$y]
                case "id"
                    $nodes[$dims][0]=$values[$y]
                Case "title"
                    $nodes[$dims][1]=$values[$y]
                Case "thumbnail_url"
                    $nodes[$dims][2]=$values[$y]
                Case "url"
                    $nodes[$dims][3]=$values[$y]
            EndSwitch
            Next
            $dims += 1
        EndIf
    Next
            _ArrayDisplay($nodes,"YouTube data")
EndIf
Func _ArrayDump($aVar,$sTitle="")
if Not IsArray($aVar) Then
    MsgBox(266288,$sTitle,"NOT AN ARRAY:"&@LF&$aVar)
Else
    MsgBox(266304,$sTitle,_ArrayToString($aVar,@LF))
EndIf
EndFunc

Prob, I just need to learn more basic autoit/scripting before diving into this; but I'll keep trying...

Keep in mind that there is no error checking in the script above.

Posted

Hi,

Like everybody else posting questions around here, I am new to XML.

I am having a hard time to figure out the use of "Arrays" when reading the return value from XMLDomWrapper.

I have an INI file that I have converted to XML:

<?xml version="1.0" encoding="utf-8"?>

<configuration>

<section name="General">

<setting name="Path" value="C:\" />

<setting name="Port" value="1033" />

<setting name="Author" value="CB11" />

<setting name="Country" value="Canada" />

</section>

<section name="Execute">

<setting name="Execute1" value="notepad.exe" />

<setting name="Execute2" value="wordpad.exe" />

</section>

</configuration>

What I am trying to achieve is to read the different setting names into variables or into an array using AU3. I have tried different ways but without success.

Could you help me get started?

Thanks

Posted (edited)

Hi,

Like everybody else posting questions around here, I am new to XML.

I am having a hard time to figure out the use of "Arrays" when reading the return value from XMLDomWrapper.

I have an INI file that I have converted to XML:

<?xml version="1.0" encoding="utf-8"?>

<configuration>

<section name="General">

<setting name="Path" value="C:\" />

<setting name="Port" value="1033" />

<setting name="Author" value="CB11" />

<setting name="Country" value="Canada" />

</section>

<section name="Execute">

<setting name="Execute1" value="notepad.exe" />

<setting name="Execute2" value="wordpad.exe" />

</section>

</configuration>

What I am trying to achieve is to read the different setting names into variables or into an array using AU3. I have tried different ways but without success.

Could you help me get started?

Thanks

This will get you started.

#Include <user/_XMLDomWrapper.au3>
#include <Array.au3>
_XMLFileOpen("settings.xml")

enum $PATH, $PORT, $AUTHOR, $COUNTRY,$MAXGEN
enum $EXEC1,$EXEC2, $MAXEXEC
Local $general[1][$MAXGEN]
Local $execute[1][$MAXEXEC]

    $general[0][  $PATH  ] = _XMLGetAttrib ('/configuration/section[@name="General"]/setting[@name="Path"]', "value") 
    $general[0][  $PORT  ] = _XMLGetAttrib ('/configuration/section[@name="General"]/setting[@name="Port"]', "value") 
    $general[0][ $AUTHOR ] = _XMLGetAttrib ('/configuration/section[@name="General"]/setting[@name="Author"]', "value") 
    $general[0][ $COUNTRY] = _XMLGetAttrib ('/configuration/section[@name="General"]/setting[@name="Country"]', "value") 
_ArrayDisplay($general,"General")
    
    $execute[0][  $EXEC1 ] = _XMLGetAttrib ('/configuration/section[@name="Execute"]/setting[@name="Execute1"]', "value") 
    $execute[0][  $EXEC2 ] = _XMLGetAttrib ('/configuration/section[@name="Execute"]/setting[@name="Execute2"]', "value") 
_ArrayDisplay($execute,"Execute")
Edited by eltorro
Posted

Thx eltorro !!

I haven't yet suceeded in acually getting this thing to work...

BUT I do understand now what to do next...

the simple 'loop' in your example explained a lot....

anyway; I'll post my progress if u/someone s interessted...

chrs,

Tito

Posted

XPath can be used to "qualify" your query results.

There are ways to use regular expressions with xml but that is beyond the my scope of knowledge at the moment.

Ok thanks, got it working using your suggestions. Only one last question I hope to get help with;

Can I use a variable in XML function? e.g. _XMLGetValue('/tv/channel[@id='$current_nowshow']/display-name')

What do I change for $current_nowshow variable to be valid?

Posted

Ok thanks, got it working using your suggestions. Only one last question I hope to get help with;

Can I use a variable in XML function? e.g. _XMLGetValue('/tv/channel[@id='$current_nowshow']/display-name')

What do I change for $current_nowshow variable to be valid?

Just concatenate the string as ususal. Pay particular attention to the quotes.

_XMLGetValue('/tv/channel[@id="'&$current_nowshow&'"]/display-name')
Posted

Thanks for your help, mostly have my TV guide script working now. One final thing I can't figure out though is;

<tv>

<programme start="200706162130" stop="200706162200" channel="43">

<title lang="en">Samurai Jack</title>

</programme>

<programme start="200706162200" stop="200706162230" channel="43">

<title lang="en">Samurai Jack</title>

</programme>

<programme start="200706162230" stop="200706162245" channel="43">

<title lang="en">Space Ghost: Coast To Coast</title>

</programme>

</tv>

If I wanted to know the title of the current programme, and had the current time eg. "200706162145", can I search the XML to find the program that has start time >= "200706162145" and end time < "200706162145"? Then I want to return the name between the <title> tags.

So for above example with current time of 200706162145, result would be Samurai Jack.

Posted (edited)

Thanks for your help, mostly have my TV guide script working now. One final thing I can't figure out though is;

<tv>

<programme start="200706162130" stop="200706162200" channel="43">

<title lang="en">Samurai Jack</title>

</programme>

<programme start="200706162200" stop="200706162230" channel="43">

<title lang="en">Samurai Jack</title>

</programme>

<programme start="200706162230" stop="200706162245" channel="43">

<title lang="en">Space Ghost: Coast To Coast</title>

</programme>

</tv>

If I wanted to know the title of the current programme, and had the current time eg. "200706162145", can I search the XML to find the program that has start time >= "200706162145" and end time < "200706162145"? Then I want to return the name between the <title> tags.

So for above example with current time of 200706162145, result would be Samurai Jack.

your could try (untested) :

_XMLGetValue('/tv/programme[@start<= "20076162145" and @stop>="20076162145"]/title')

edit: Changes the attrib names to match the xml.

Edited by eltorro
Posted (edited)

your could try (untested) :

_XMLGetValue('/tv/programme[@start<= "20076162145" and @stop>="20076162145"]/title')

edit: Changes the attrib names to match the xml.

Ok, so using AND and OR etc is ok inside the [], cool.

I am getting the following error:

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

F:\PROGRA~1\AutoIt3\autoit3.exe

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

COM Error with DOM!

err.description is: Expected token ']' found 'NAME'.

/tv/programme[@start<= "200706162115" -->AND <--@stop>"200706162115"]/title

err.windescription: Unspecified error

err.number is: 80020009

err.lastdllerror is: 0

err.scriptline is: 337

err.source is: msxml6.dll

err.helpfile is:

err.helpcontext is: 0

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

OK

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

When I use:

_XMLGetValue('/tv/programme[@start<= "200706162115" AND @stop>"200706162115"]/title')

With this XML:

<tv>

<programme start="200706162100" stop="200706162130" channel="42">

<title lang="en">SpongeBob SquarePants</title>

<sub-title lang="en">SpongeBob reads a 'bad' word off a dumpster</sub-title>

<desc lang="en">Thinking it's a fancy word, he and Patrick start using it in every sentence. Squid is teaching an art class and SpongeBob turns up as his only student.</desc>

<category>Children</category>

<category>Youth Programmes</category>

<rating system="NZ">

<value>PG</value>

</rating>

</programme>

</tv>

Edited by rickd
Posted

Ok, so using AND and OR etc is ok inside the [], cool.

I am getting the following error:

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

F:\PROGRA~1\AutoIt3\autoit3.exe

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

COM Error with DOM!

err.description is: Expected token ']' found 'NAME'.

/tv/programme[@start<= "200706162115" -->AND <--@stop>"200706162115"]/title

err.windescription: Unspecified error

err.number is: 80020009

err.lastdllerror is: 0

err.scriptline is: 337

err.source is: msxml6.dll

err.helpfile is:

err.helpcontext is: 0

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

OK

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

When I use:

_XMLGetValue('/tv/programme[@start<= "200706162115" AND @stop>"200706162115"]/title')

With this XML:

<tv>

<programme start="200706162100" stop="200706162130" channel="42">

<title lang="en">SpongeBob SquarePants</title>

<sub-title lang="en">SpongeBob reads a 'bad' word off a dumpster</sub-title>

<desc lang="en">Thinking it's a fancy word, he and Patrick start using it in every sentence. Squid is teaching an art class and SpongeBob turns up as his only student.</desc>

<category>Children</category>

<category>Youth Programmes</category>

<rating system="NZ">

<value>PG</value>

</rating>

</programme>

</tv>

msxml is case sensitive.

#Include <user/_XMLDomWrapper.au3>
#include <Array.au3>

_XMLFileOpen("tv2.xml")
;------------------------------------------------------------
$var = _XMLGetValue('/tv/programme[(@start<= "200706162115") and (@stop>"200706162115")]/title')
_ArrayDump($var,"/tv/programme")

$var = _XMLGetValue('/tv/programme[@start<= "200706162115" and @stop>"200706162115"]/title')
_ArrayDump($var,"/tv/programme")

$sub =  _XMLGetValue('/tv/programme[@start<= "200706162115" and @stop>"200706162115"]/sub-title')
$desc =  _XMLGetValue('/tv/programme[@start<= "200706162115" and @stop>"200706162115"]/desc')
;-------------------------------------------------------------

$msg =StringFormat("%s\n\n%s\n\n%s",$var[1],$sub[1],$desc[1])
MsgBox(266288,"Now Showing",$msg)

Func _ArrayDump($aVar,$sTitle="")
if Not IsArray($aVar) Then
    MsgBox(266288,$sTitle,"NOT AN ARRAY:"&@LF&$aVar)
Else
    MsgBox(266304,$sTitle,_ArrayToString($aVar,@LF))
EndIf
EndFunc

The above works for me with the XML you posted

Posted

Hello,

I am pretty new to Autoit and XML and just cant seem to figure out how to do what I want to do.

What I want to do is create a script that will grab the logged in user ID and import it in the xml file so that it follows the following format.

<Export_Filename>\\Server\Folder\LoggedOnUser.txt</Export_Filename>

Here is a copy of the xml file that I would like to edit. The part I would like to edit is under MISC at the bottom.

<?xml version="1.0" standalone="yes" ?>

- <ScreenConfigDataSet xmlns="http://tempuri.org/ScreenConfigDataSet.xsd">

- <SCREEN>

<Name>Default</Name>

<Sort_Column_Name>TICKET_Due_DateTime</Sort_Column_Name>

<Sort_Ascending>1</Sort_Ascending>

<Has_Ticket_Type_Image>1</Has_Ticket_Type_Image>

<Has_DueTime_Image>1</Has_DueTime_Image>

<Has_Status_Image>1</Has_Status_Image>

<Has_Sync_Indicator_Image>1</Has_Sync_Indicator_Image>

<Has_Attachment_Image>0</Has_Attachment_Image>

<Has_NonComplantExcv_Image>1</Has_NonComplantExcv_Image>

<Create_DateTime>2007-06-08T11:31:40.7655503-07:00</Create_DateTime>

<Update_DateTime>2007-06-08T11:31:40.7655503-07:00</Update_DateTime>

<Position_X>22</Position_X>

<Position_Y>1</Position_Y>

<Width>1024</Width>

<Height>780</Height>

<Is_Maximized>true</Is_Maximized>

- <SCREEN_ITEM>

<Field_Name>Ticket ID</Field_Name>

<Table_Name>TICKET</Table_Name>

<Column_Name>OCC_Ticket_ID</Column_Name>

<Display_Order>6</Display_Order>

<Width>100</Width>

</SCREEN_ITEM>

- <SCREEN_ITEM>

<Field_Name>Facility</Field_Name>

<Table_Name>TICKET_LOCATE_INFO</Table_Name>

<Column_Name>Facility_Name</Column_Name>

<Display_Order>1</Display_Order>

<Width>100</Width>

</SCREEN_ITEM>

- <SCREEN_ITEM>

<Field_Name>Excavator Name</Field_Name>

<Table_Name>TICKET</Table_Name>

<Column_Name>Excavator_Name</Column_Name>

<Display_Order>7</Display_Order>

<Width>100</Width>

</SCREEN_ITEM>

- <SCREEN_ITEM>

<Field_Name>Place</Field_Name>

<Table_Name>DIGSITE_ITEM</Table_Name>

<Column_Name>Place</Column_Name>

<Display_Order>8</Display_Order>

<Width>100</Width>

</SCREEN_ITEM>

- <SCREEN_ITEM>

<Field_Name>Address</Field_Name>

<Table_Name>STREET</Table_Name>

<Column_Name>Full_Address</Column_Name>

<Display_Order>9</Display_Order>

<Width>100</Width>

</SCREEN_ITEM>

- <SCREEN_ITEM>

<Field_Name>Due Time</Field_Name>

<Table_Name>TICKET</Table_Name>

<Column_Name>Due_DateTime</Column_Name>

<Display_Order>10</Display_Order>

<Width>100</Width>

</SCREEN_ITEM>

- <SCREEN_ITEM>

<Field_Name>Near Street</Field_Name>

<Table_Name>NEAR_STREET</Table_Name>

<Column_Name>Full_Address</Column_Name>

<Display_Order>11</Display_Order>

<Width>100</Width>

</SCREEN_ITEM>

- <SCREEN_ITEM>

<Field_Name>Creation Time</Field_Name>

<Table_Name>TICKET</Table_Name>

<Column_Name>Create_DateTime</Column_Name>

<Display_Order>12</Display_Order>

<Width>100</Width>

</SCREEN_ITEM>

</SCREEN>

- <MISC>

<Misc_ID>0</Misc_ID>

<Export_Filename>\\Server\Folder\LoggedOnUser.txt</Export_Filename>

<Response_Complete_Flag>1</Response_Complete_Flag>

<Export_External_Routing_Filename>C:\DATA\Routing.txt</Export_External_Routing_Filename>

</MISC>

</ScreenConfigDataSet>

Can someone please help?

Thank you,

Robert

Posted

Hello,

I am pretty new to Autoit and XML and just cant seem to figure out how to do what I want to do.

What I want to do is create a script that will grab the logged in user ID and import it in the xml file so that it follows the following format.

<Export_Filename>\\Server\Folder\LoggedOnUser.txt</Export_Filename>

Here is a copy of the xml file that I would like to edit. The part I would like to edit is under MISC at the bottom.

<?xml version="1.0" standalone="yes" ?>

- <ScreenConfigDataSet xmlns="http://tempuri.org/ScreenConfigDataSet.xsd">

- <SCREEN>

<Name>Default</Name>

<Sort_Column_Name>TICKET_Due_DateTime</Sort_Column_Name>

<Sort_Ascending>1</Sort_Ascending>

<Has_Ticket_Type_Image>1</Has_Ticket_Type_Image>

<Has_DueTime_Image>1</Has_DueTime_Image>

<Has_Status_Image>1</Has_Status_Image>

<Has_Sync_Indicator_Image>1</Has_Sync_Indicator_Image>

<Has_Attachment_Image>0</Has_Attachment_Image>

<Has_NonComplantExcv_Image>1</Has_NonComplantExcv_Image>

<Create_DateTime>2007-06-08T11:31:40.7655503-07:00</Create_DateTime>

<Update_DateTime>2007-06-08T11:31:40.7655503-07:00</Update_DateTime>

<Position_X>22</Position_X>

<Position_Y>1</Position_Y>

<Width>1024</Width>

<Height>780</Height>

<Is_Maximized>true</Is_Maximized>

- <SCREEN_ITEM>

<Field_Name>Ticket ID</Field_Name>

<Table_Name>TICKET</Table_Name>

<Column_Name>OCC_Ticket_ID</Column_Name>

<Display_Order>6</Display_Order>

<Width>100</Width>

</SCREEN_ITEM>

- <SCREEN_ITEM>

<Field_Name>Facility</Field_Name>

<Table_Name>TICKET_LOCATE_INFO</Table_Name>

<Column_Name>Facility_Name</Column_Name>

<Display_Order>1</Display_Order>

<Width>100</Width>

</SCREEN_ITEM>

- <SCREEN_ITEM>

<Field_Name>Excavator Name</Field_Name>

<Table_Name>TICKET</Table_Name>

<Column_Name>Excavator_Name</Column_Name>

<Display_Order>7</Display_Order>

<Width>100</Width>

</SCREEN_ITEM>

- <SCREEN_ITEM>

<Field_Name>Place</Field_Name>

<Table_Name>DIGSITE_ITEM</Table_Name>

<Column_Name>Place</Column_Name>

<Display_Order>8</Display_Order>

<Width>100</Width>

</SCREEN_ITEM>

- <SCREEN_ITEM>

<Field_Name>Address</Field_Name>

<Table_Name>STREET</Table_Name>

<Column_Name>Full_Address</Column_Name>

<Display_Order>9</Display_Order>

<Width>100</Width>

</SCREEN_ITEM>

- <SCREEN_ITEM>

<Field_Name>Due Time</Field_Name>

<Table_Name>TICKET</Table_Name>

<Column_Name>Due_DateTime</Column_Name>

<Display_Order>10</Display_Order>

<Width>100</Width>

</SCREEN_ITEM>

- <SCREEN_ITEM>

<Field_Name>Near Street</Field_Name>

<Table_Name>NEAR_STREET</Table_Name>

<Column_Name>Full_Address</Column_Name>

<Display_Order>11</Display_Order>

<Width>100</Width>

</SCREEN_ITEM>

- <SCREEN_ITEM>

<Field_Name>Creation Time</Field_Name>

<Table_Name>TICKET</Table_Name>

<Column_Name>Create_DateTime</Column_Name>

<Display_Order>12</Display_Order>

<Width>100</Width>

</SCREEN_ITEM>

</SCREEN>

- <MISC>

<Misc_ID>0</Misc_ID>

<Export_Filename>\\Server\Folder\LoggedOnUser.txt</Export_Filename>

<Response_Complete_Flag>1</Response_Complete_Flag>

<Export_External_Routing_Filename>C:\DATA\Routing.txt</Export_External_Routing_Filename>

</MISC>

</ScreenConfigDataSet>

Can someone please help?

Thank you,

Robert

I was able to get it to update the XML file using

_XMLUPDATEFIELD('ScreenConfigDataSet/MISC/Export_Filename',"\\server\folder\" & @UserName & ".txt")

But only if I got rid of the Attributes(xmlns="http://tempuri.org/ScreenConfigDataSet.xsd">).

With the Attributes intact I get the following error

Failed to update field for: ScreenConfigDataSet/MISC/Export_Filename

Error Selecting Node(s): ScreenConfigDataSet/MISC

No Matching Nodes found

How do I import the data while having the attributes intact?

Posted

I was able to get it to update the XML file using

_XMLUPDATEFIELD('ScreenConfigDataSet/MISC/Export_Filename',"\\server\folder\" & @UserName & ".txt")

But only if I got rid of the Attributes(xmlns="http://tempuri.org/ScreenConfigDataSet.xsd">).

With the Attributes intact I get the following error

Failed to update field for: ScreenConfigDataSet/MISC/Export_Filename

Error Selecting Node(s): ScreenConfigDataSet/MISC

No Matching Nodes found

How do I import the data while having the attributes intact?

I figured it out after reading "http://www.xml.com/pub/a/2004/02/25/qanda.html" which was posted in this forum.

thank you,

Robert

P.S. I really am thankful that you created the XML DOM wrapper. It works very well.

Posted

I'm trying to use UDF version 1.2.0.19. But somehow all the code posted in this thread ends up being invalid... Is that correct? Should that happen?

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
  • Recently Browsing   0 members

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