luvan wrote:
I can not find XMLRead function from Titan

As I recall, Titan lost or deleted most of his xml code and docs (you might PM him (or catch him on the #ahk irc channel) and ask if he still has the code), so here is what I had saved way back on 12/25/2007.
--------------------------------------------------------------------------------
Here is XMLRead() v2.04
Code:
XMLRead(source, tree, default = "") { ; v2.04 - by Titan
If source is integer
{
DllCall("SetFilePointer", "UInt", source, "UInt", 0, "UInt", 0, "UInt", 0)
s := VarSetCapacity(c, DllCall("GetFileSize", "UInt", source, "UInt", 0))
DllCall("ReadFile", "UInt", source, "Str", c, "UInt", s, "UIntP", s, "UInt", 0)
}
Else FileRead, c, %source%
StringGetPos, t, tree, @
If (ErrorLevel = 0) {
StringTrimLeft, a, tree, t + 1
StringLeft, tree, tree, t
}
xc = %A_StringCaseSense%
StringCaseSense, On
d = >/%A_Tab%`r`n
Loop, Parse, tree, .
{
e = %A_LoopField%
i = 1
StringGetPos, t, e, (
If (ErrorLevel = 0) {
StringMid, i, e, t + 2, InStr(e, ")") - t - 2
StringLeft, e, e, t
i++
}
Loop, Parse, d
StringReplace, c, c, <%e%%A_LoopField%, <%e% %A_LoopField%, A
ex := "<" . e . " "
n = %A_Index%
Loop {
StringTrimLeft, c, c, InStr(c, ex, 1) -
StringReplace, c, c, <, <, UseErrorLevel
t = %ErrorLevel%
StringReplace, c, c, />, />, UseErrorLevel
t -= ErrorLevel
StringReplace, c, c, </, </, UseErrorLevel
If (t - ErrorLevel * 2) * -1 - n < 0 or x
Break
Else StringTrimLeft, c, c, 1
}
StringGetPos, t, c, %ex%, L%i%
x += ErrorLevel
StringTrimLeft, c, c, t
t := InStr(c, "</" . e, 1)
IfNotEqual, t, 0, StringLeft, c, c, t + StrLen(e) + 2
}
If a
x := !(RegExMatch(c, ex . "[^>]*" . a . "=('|"")(.*?)\1", d) and c := d2)
Else {
t := InStr(c, "</" . e . ">", 1)
x += !t
StringMid, c, c, InStr(c, ">") + 1, t - 1 - InStr(c, ">")
}
StringCaseSense, %xc%
If x
c = %default%
Return, c
}
and here is the doc page I saved
Code:
XMLRead() [version 2.0]
------------------------------------
Reads data from an XML document.
Result := XMLRead(Source, Tree [, Default])
Parameters
Result The actual value returned by the function.
Source The name or handle of the file to read from. Performance is dramatically improved when using a file handle.
Tree The complete path of the node using the format parent.child(index)@attribute where each index starts at 0.
Default The value to return if there is an error.
Related
FileRead, IniRead, RegRead, XMLWrite(), XML Tutorial
Examples
; Example 1: get settings from a custom XML file
settings = settings.xml ; file name
version := XMLRead(settings, "application@version") ; 'version' attribute of 'application'
tip_colour := XMLRead(settings, "application.interface.control(2).colour") ; third index of 'control'
close_msg := XMLRead(settings, "application.messages.close", "Closing...") ; using default value of 'Closing...'
; Example 2: aggregate a list of most-downloaded programs on download.com
#Include XMLRead.ahk ; includes the function
title = XML Reader Example
href = http://export.cnet.com/export/download/rss-hot-download.com.com.xml
TrayTip, %title% - Downloading...
, Downloading RSS XML from:`n%href%, 10, 1
file = %A_Temp%\cnet_%A_Now%.xml
URLDownloadToFile, %href%, %file%
If ErrorLevel { ; if download was unsucessful...
TrayTip
MsgBox, 18, %title% - Error, Downloading failed?, 5
IfMsgBox, Abort
ExitApp
IfMsgBox, Retry
Reload
}
Gui, Font, s14 underline
Gui, Add, Text, vTitle gVisitMain, % XMLRead(file, "rss.channel.title") ; RSS title
Gui, Font
Gui, Add, ListView, w600 r10 gVisit, #|Title|Description|Published
items = 7 ; there number of item elements to parse ...
Loop, %items% {
LV_Add("", A_Index
, XMLRead(file, "rss.channel.item(" . A_Index - 1 . ").title") ; item title
, XMLRead(file, "rss.channel.item(" . A_Index - 1 . ").description") ; item description
, XMLRead(file, "rss.channel.item(" . A_Index - 1 . ").pubDate")) ; item pubdate (date published)
link%A_Index% := XMLRead(file, "rss.channel.item(". A_Index - 1 . ").link") ; store the item URL
}
IL := IL_Create(items)
LV_SetImageList(IL)
Loop, %items%
IL_Add(IL, "shell32.dll", 14)
Loop, 4
LV_ModifyCol(A_Index, "AutoHdr") ; auto-adjust columns
basex := XMLRead(file, "rss.channel.link") ; main URL
SplitPath, basex, , , , , base
StringReplace, base, base, http://
StringReplace, base, base, www.
StringReplace, base, base, /
Gui, Add, Button, Section w50 gGuiClose Default, &Close
Gui, Add, Text, ys+5, Double-click an item to view it on %base%
RSS := XMLRead(file, "rss@version") ; RSS version (attribute)
FileDelete, %file%
TrayTip
Gui, Show, , %title% - RSS Version %RSS%
Return
VisitMain:
Run, %basex%
Return
Visit:
If A_GuiEvent = DoubleClick
Run, % link%A_EventInfo% ; opens item's link
Return
GuiClose:
ExitApp