AutoHotkey Community

It is currently May 26th, 2012, 5:40 pm

All times are UTC [ DST ]




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 417 posts ]  Go to page Previous  1 ... 24, 25, 26, 27, 28  Next
Author Message
 Post subject:
PostPosted: April 23rd, 2009, 6:29 pm 
Offline

Joined: March 19th, 2009, 4:04 pm
Posts: 9
Well, I have for myself still some unresolved issues with xpath3. Hyphen (see above) and case-sensitivity seem to be problems, but just taking a very quick look at your code, I would assume that you need to assign your loaded file to a variable.

In your case xmlfile. You use it in
Code:
xpath(xmlfile, "settings/history_store() ", "true")


so in my understanding you would have to load it like this, before you use the xpath command above
Code:
xpath_load(xmlfile, %A_LoopFileFullPath%)


Cheers
Greg

Edit:
Same thing when you save the xml. Where do you assign the variable "feed"? Also wrong order of parameters. Please look at the reference included with xpath.ahk.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 24th, 2009, 5:38 pm 
Offline

Joined: March 18th, 2009, 3:06 pm
Posts: 17
Location: Minnesota, USA
Hi Gregster,
Thanks for taking the time to look at it. It's probably obvious, but I've only been using AHK for a couple of months now and have no previous programming experience, so I apologize for stupid questions/mistakes.

I did find another way to accomplish what I need for this task, however I would really like to understand how to use xpath correctly. I corrected a few things... I think. The variable feed was wrong, like you said. I copied that line from the example without understanding that it was a variable.

I didn't understand what you meant exactly by wrong order of parameters. I looked the reference included with xpath, this thread and my code for about 6 hours yesterday trying different things. Hopefully I didn't screw it up more.

Here's my current solution that works for me right now, but I'd like to use xpath for future projects. Maybe it will be useful to others for small xml files without similar entries.

Code:
#NoTrayIcon


Loop, %A_AppData%\Pandion\Profiles\settings.xml, , 1  ; Recurse into subfolders.
{
   FileRead, incomingfile, %A_LoopFileFullPath%
   StringReplace, outgoingfile, incomingfile, <history_store>false</history_store>, <history_store>true</history_store>,



   FileDelete, %A_LoopFileFullPath%
 
FileAppend, %outgoingfile%, %A_LoopFileFullPath%


Here's my current xpath script that's broken
Code:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#include xpath.ahk





Loop, %A_AppData%\Pandion\Profiles\settings.xml, , 1  ; Recurse into subfolders.

{
    xpath_load(xmlfile, %A_LoopFileFullPath%)
    xpath(xmlfile, "settings/history_store/text() ", "true")
   
   
   
    MsgBox, 4, , Filename = %A_LoopFileFullPath%`n`nContinue?
    IfMsgBox, No
        break

   
    xpath_save(%A_LoopFileFullPath%, xmlfile) ; write XML
   
}



And here's the error
---------------------------
PandionUserUpdateXpath.ahk
---------------------------
Error: The following variable name contains an illegal character:
"\\server\RedirectedFolders\user\Application Data\Pandion\Profiles\admin@chat.domain.local\settings.xml"

The current thread will exit.

Line#
448: }
449: StringReplace,doc,xml,,,,,All
450: NumPut(0, doc := " " . doc, 0, "UChar")
451: Return,true
452: }
011: Loop,%A_AppData%\Pandion\Profiles\settings.xml,,1
013: {
---> 014: xpath_load(xmlfile, %A_LoopFileFullPath%)
015: xpath(xmlfile, "settings/history_store/text() ", "true")
019: MsgBox,4,,Filename = %A_LoopFileFullPath%

Continue?
020: IfMsgBox,No
021: Break
024: xpath_save(%A_LoopFileFullPath%, xmlfile)
026: }
026: Exit

---------------------------
OK
---------------------------


If I take both of the % out of line 14 I get this. It looks like it gets past the loading file portion, but I'm not sure that it's storing it in the variable xmlfile. If I view variables at the point where it displays the dialog box I get this.

Global Variables (alphabetical)
--------------------------------------------------
0[1 of 3]: 0
ErrorLevel[1 of 3]: 0
xmlfile[4143 of 4556]: ...



Here's the output from AHK



Code:
Script lines most recently executed (oldest first).  Press [F5] to refresh.  The seconds elapsed between a line and the one after it is in parentheses to the right (if not 0).  The bottommost line's elapsed time is the number of seconds since it executed.

437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
444: pre = %pre%%tag%/
445: xml = %xml%<%pre%:: %ex%
446: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
439: xml = %xml%</%pre%%ex%
440: StringGetPos,pos,pre,/,R2
441: StringLeft,pre,pre,pos + 1
442: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
444: pre = %pre%%tag%/
445: xml = %xml%<%pre%:: %ex%
446: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
439: xml = %xml%</%pre%%ex%
440: StringGetPos,pos,pre,/,R2
441: StringLeft,pre,pre,pos + 1
442: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
444: pre = %pre%%tag%/
445: xml = %xml%<%pre%:: %ex%
446: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
439: xml = %xml%</%pre%%ex%
440: StringGetPos,pos,pre,/,R2
441: StringLeft,pre,pre,pos + 1
442: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
444: pre = %pre%%tag%/
445: xml = %xml%<%pre%:: %ex%
446: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
439: xml = %xml%</%pre%%ex%
440: StringGetPos,pos,pre,/,R2
441: StringLeft,pre,pre,pos + 1
442: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
444: pre = %pre%%tag%/
445: xml = %xml%<%pre%:: %ex%
446: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
439: xml = %xml%</%pre%%ex%
440: StringGetPos,pos,pre,/,R2
441: StringLeft,pre,pre,pos + 1
442: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
444: pre = %pre%%tag%/
445: xml = %xml%<%pre%:: %ex%
446: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
439: xml = %xml%</%pre%%ex%
440: StringGetPos,pos,pre,/,R2
441: StringLeft,pre,pre,pos + 1
442: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
444: pre = %pre%%tag%/
445: xml = %xml%<%pre%:: %ex%
446: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
439: xml = %xml%</%pre%%ex%
440: StringGetPos,pos,pre,/,R2
441: StringLeft,pre,pre,pos + 1
442: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
444: pre = %pre%%tag%/
445: xml = %xml%<%pre%:: %ex%
446: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
439: xml = %xml%</%pre%%ex%
440: StringGetPos,pos,pre,/,R2
441: StringLeft,pre,pre,pos + 1
442: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
444: pre = %pre%%tag%/
445: xml = %xml%<%pre%:: %ex%
446: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
439: xml = %xml%</%pre%%ex%
440: StringGetPos,pos,pre,/,R2
441: StringLeft,pre,pre,pos + 1
442: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
444: pre = %pre%%tag%/
445: xml = %xml%<%pre%:: %ex%
446: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
439: xml = %xml%</%pre%%ex%
440: StringGetPos,pos,pre,/,R2
441: StringLeft,pre,pre,pos + 1
442: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
444: pre = %pre%%tag%/
445: xml = %xml%<%pre%:: %ex%
446: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
439: xml = %xml%</%pre%%ex%
440: StringGetPos,pos,pre,/,R2
441: StringLeft,pre,pre,pos + 1
442: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
444: pre = %pre%%tag%/
445: xml = %xml%<%pre%:: %ex%
446: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
439: xml = %xml%</%pre%%ex%
440: StringGetPos,pos,pre,/,R2
441: StringLeft,pre,pre,pos + 1
442: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
444: pre = %pre%%tag%/
445: xml = %xml%<%pre%:: %ex%
446: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
439: xml = %xml%</%pre%%ex%
440: StringGetPos,pos,pre,/,R2
441: StringLeft,pre,pre,pos + 1
442: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
444: pre = %pre%%tag%/
445: xml = %xml%<%pre%:: %ex%
446: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
439: xml = %xml%</%pre%%ex%
440: StringGetPos,pos,pre,/,R2
441: StringLeft,pre,pre,pos + 1
442: }
447: }
448: }
418: if (A_Index == 2 &&  InStr(A_LoopField, "?xml") == 1) 
420: if (InStr(A_LoopField, "?") == 1) 
422: if (InStr(A_LoopField, "![CDATA[") == 1) 
431: if (!pos := RegExMatch(A_LoopField, "^\/?(?:\w+:)?\w+", tag)) 
437: StringMid,ex,A_LoopField,pos + StrLen(tag)
438: if InStr(tag, "/") = 1 
439: xml = %xml%</%pre%%ex%
440: StringGetPos,pos,pre,/,R2
441: StringLeft,pre,pre,pos + 1
442: }
447: }
448: }
449: StringReplace,doc,xml,,,,,All
450: NumPut(0, doc := " " . doc, 0, "UChar") 
451: Return,true
015: xpath(xmlfile, "settings/history_store/text() ", "true") 
035: if step contains %scb%
037: sid := scb . &doc . ":"
038: if (InStr(step, "select:") == 1) 
042: if (InStr(step, "/") == 1) 
045: StringGetPos,p,sc,%sid%
046: if ErrorLevel = 1
047: t = /
049: step = %t%/%step%
050: }
053: step := RegExReplace(step, "(?<=^|/)(?:[^\[/@]+/\.{2}|\.)(?:/|$)|^.+(?=//)")
055: if (str == 1 || stsl == 1) 
068: if (InStr(step, "|")) 
074: if (InStr(step, "//") == 1) 
075: StringTrimLeft,step,step,2
076: re = 1
077: rew = 1
078: xp = /(?:(?:\w+:)?\w+)*/
079: }
081: NumPut(160, doc, 0, "UChar") 
084: Loop,Parse,step,/
086: s = %A_LoopField%
087: if (InStr(s, "*") == 1) 
092: if (InStr(s, "@") == 1) 
096: StringGetPos,p,s,[
097: if ErrorLevel = 0
147: if (InStr(s, "()")) 
152: xp = %xp%%s%/
153: }
086: s = %A_LoopField%
087: if (InStr(s, "*") == 1) 
092: if (InStr(s, "@") == 1) 
096: StringGetPos,p,s,[
097: if ErrorLevel = 0
147: if (InStr(s, "()")) 
152: xp = %xp%%s%/
153: }
086: s = %A_LoopField%
087: if (InStr(s, "*") == 1) 
092: if (InStr(s, "@") == 1) 
096: StringGetPos,p,s,[
097: if ErrorLevel = 0
147: if (InStr(s, "()")) 
148: fn = %fn%+%s%
149: Continue
155: if (xp == "" || xp == "/") 
159: StringTrimLeft,xp,xp,1
160: StringTrimRight,ax,ax,1
162: StringTrimRight,nw,nw,1
164: ct = 0
165: os = 0
166: Loop
168: if re 
169: os := RegExMatch(doc, "<" . xp . ":: ", "", 1 + os), osx := RegExMatch(doc, "</" . xp . ">", rem, os) + StrLen(rem) 
175: if os = 0
176: Break
300: if setb <>
321: if (InStr(fn, "+count()")) 
324: nsid := scb . &doc . ":"
325: if nsid <> %sid%
328: NumPut(0, doc, 0, "UChar") 
329: StringTrimRight,res,res,1
330: if (InStr(fn, "+rawsrc()")) 
338: Return,RegExReplace(res, "S)(?<=<)(\/)?(?:(\w+)\/)+(?(1)|:: )", "$1$2")
019: MsgBox,4,,Filename = %A_LoopFileFullPath% Contents = %xmlfile%

Continue? (47.72)
020: IfMsgBox,No
024: xpath_save(%A_LoopFileFullPath%, xmlfile)   (17.67)

Press [F5] to refresh.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 24th, 2009, 6:37 pm 
Offline

Joined: March 19th, 2009, 4:04 pm
Posts: 9
hi pkutter,
first of all, I'm not really an expert like others here (I just started in february, but did some simple programming at university years ago), but I think we will get your script working with xpath3 sooner or later.

I admit that the examples in the reference are not all correct. As far as I can see Titan changed some things in version 3 of xpath but didn't change all the examples to the new syntax.

I'm not sure about your loop because I don't know your file structure, but maybe try this simple example first:

A simple xml file for testing:
Code:
<settings>
   <history_store>false</history_store>
   <other>three</other>
</settings>

Just save it as test.xml in a folder.

Then save this simple script in the same folder:
Code:
; loads the contents of the file to the variable xmlfile
xpath_load(xmlfile, "test.xml")

  ; read the old text int the variable var
   var   := xpath(xmlfile, "/settings/history_store/text()")   
   msgbox %var%   

  ; write the new text
   xpath(xmlfile, "/settings/history_store/text()", "true")

  ; check if it worked
   var   := xpath(xmlfile, "/settings/history_store/text()")   
   msgbox %var%   

; now save it to a new file , you could also overwrite the old one
xpath_save(xmlfile, "test_changed.xml" )


As you can see, I changed two important things compared to your script:
Code:
xpath_save(xmlfile, "test_changed.xml" )

instead of
Code:
xpath_save(%A_LoopFileFullPath%, xmlfile)

That's what I meant by wrong order of parameters.

Also I added a slash "/" before settings. Without it, it won't work. So hopefully this example helps you to get your script working. Otherwise feel free to ask again...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 11th, 2009, 4:38 pm 
Offline

Joined: March 18th, 2009, 3:06 pm
Posts: 17
Location: Minnesota, USA
Hi Gregster,
Thanks for all of the help. I appreciate it, but I think I'm giving up on xpath for now. I've spent too much time on it, and the simpler, less elegant solution works for now. I may revisit if I find another use for writing an xml file.

Pete


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2009, 11:45 am 
Offline

Joined: December 7th, 2005, 8:29 am
Posts: 345
Hi.

A quick question.

I am trying to get all the text from the title element in this xml file:
http://www.apple.com/trailers/home/xml/widgets/indexall.xml

Code:
<?xml version="1.0" encoding="utf-8"?>
<records>
  <movieinfo id="3143" fandangoid="121134">
    <info>
      <title>$9.99</title>
      <runtime>2:09</runtime>
    </info>
    <posters>
      <poster type="normal">http://images.apple.com/moviesxml/s/independent/posters/999_200905071342.jpg</poster>
    </posters>
    <previews>
      <preview type="medium" height="260">http://movies.apple.com/movies/independent/999/999-tlr_h.480.mov</preview>
    </previews>
  </movieinfo>
  <movieinfo id="2327" fandangoid="98264">
    <info>
      <title>10,000 B.C.</title>
      <runtime>2:21</runtime>
    </info>
    <posters>
      <poster type="normal">http://images.apple.com/moviesxml/s/wb/posters/10000bc_200801081614.jpg</poster>
    </posters>
    <previews>
      <preview type="medium" height="204">http://movies.apple.com/movies/wb/10000_bc/10000_bc-tlr2_h.480.mov</preview>
    </previews>
  </movieinfo>
</records>


If i use this code to get the list into a txt file:
Code:
#include %A_ScriptDir%\xpath.ahk

Xml_SRC=%A_scriptDir%\Temp\movies.xml

xpath_load(X_file, Xml_SRC)


Total_Movies:=xpath(X_file,"/records/movieinfo/count()")

Msgbox, Total Movies Found: %Total_Movies%

Loop, %Total_Movies%
{
 Title_text:=xpath(X_file,"/records/movieinfo[" . A_Index . "]/info/title/text()")
 FileAppend, %Title_text%`n, %A_ScriptDir%\temp\XML_Titles.txt
}


It takes lots of time (a lot is i never saw it ends i had to kill it)


But if i use this code which is not the clean way to do it, it works fast:
Code:
#include %A_ScriptDir%\xpath.ahk

Xml_SRC=%A_scriptDir%\Temp\movies.xml

xpath_load(X_file, Xml_SRC)

Title_text:=xpath(X_file,"/records/movieinfo/info/title/text()")
FileAppend, %Title_text%`n, %A_ScriptDir%\temp\XML_Titles.txt

FileReadLine, Test, %A_ScriptDir%\temp\XML_Titles.txt, 1
StringReplace, test, test, `,, `r`n, A

Fileappend, %Test%, %A_ScriptDir%\temp\XML_Titles1.txt


Here is another way:
Code:
#include %A_ScriptDir%\xpath.ahk

Xml_SRC=%A_scriptDir%\Temp\movies.xml

xpath_load(X_file, Xml_SRC)


Total_Movies:=xpath(X_file,"/records/movieinfo/count()")

Msgbox, Total Movies Found: %Total_Movies%


Title_text:=xpath(X_file,"/records/movieinfo/info/title/text()")

Loop, Parse, Title_text , `,
{
  FileAppend, %A_LoopField%`n, %A_ScriptDir%\temp\XML_Titles.txt
}


The difference between to codes is that the first one checks how many movies there are in the xml and then loops accordingly and grabs the text with A_Index as the variable.

The second and third one just grabs all titles and then place every thing in a comma separated line and then uses string replace to get the proper formatting.

is that how it suppose to work?
Can't XPath handle big XML files?

One more question

How can i get the preview url for a specific title?
Code:
<?xml version="1.0" encoding="utf-8"?>
<records>
  <movieinfo id="3143" fandangoid="121134">
    <info>
      <title>$9.99</title>
      <runtime>2:09</runtime>
    </info>
    <posters>
      <poster type="normal">http://images.apple.com/moviesxml/s/independent/posters/999_200905071342.jpg</poster>
    </posters>
    <previews>
      <preview type="medium" height="260">http://movies.apple.com/movies/independent/999/999-tlr_h.480.mov</preview>
    </previews>
  </movieinfo>
 
  <movieinfo id="2327" fandangoid="98264">
    <info>
      <title>10,000 B.C.</title>
      <runtime>2:21</runtime>
    </info>
    <posters>
      <poster type="normal">http://images.apple.com/moviesxml/s/wb/posters/10000bc_200801081614.jpg</poster>
    </posters>
    <previews>
      <preview type="medium" height="204">http://movies.apple.com/movies/wb/10000_bc/10000_bc-tlr2_h.480.mov</preview>
    </previews>
  </movieinfo>
</records>


Code:
trailer_url:=xpath(X_File, "/records/movieinfo/info/title/[title=$9.99]/previews/preview/text()")


I just want to get the url if the title matches.


Hope you can help me :D
Twhyman

_________________
(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 3rd, 2009, 10:16 pm 
Offline

Joined: January 7th, 2009, 9:25 pm
Posts: 18
How do I write/read to an xml file?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 26th, 2009, 4:01 pm 
Offline

Joined: June 23rd, 2009, 12:57 pm
Posts: 10
Hello;

i use a simple Xpath code in a script

I don't know how to set a variable in the xpath() like this

Code:
IniRead, PlaceMintPath, WamSkins.ini, Config, IPlaceMintPath

XmlSrc = %PlaceMintPath%\PlaceMint_settings.config
xpath_load(xmlfile, XmlSrc)

If (Deux = 1)
{
   FileCfg=%PlaceMintPath%\PlaceMint_WindowGroups_2t.config
   ; Write new text
   xpath(xmlfile, "/AppSettings/ConfigFileName/text()", %FileCfg%)
   ; save it
   xpath_save(xmlfile, Xml_SRC)   
}
Else If (Quatre = 1)
{
   FileCfg=%PlaceMintPath%\PlaceMint_WindowGroups_4t.config
   ; write the new text
   xpath(xmlfile, "/AppSettings/ConfigFileName/text()", %FileCfg%)
   ; Save it
   xpath_save(xmlfile, Xml_SRC)   
}


so how to define a varibale to set a new name ?
xpath(xmlfile, "/AppSettings/ConfigFileName/text()", %FileCfg%)

Doesn't work


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 26th, 2009, 4:08 pm 
Offline

Joined: June 23rd, 2009, 12:57 pm
Posts: 10
pfff I'm crazy !!

of course as it is a function the % has not to be set !!

Code:
xpath(xmlfile, "/AppSettings/ConfigFileName/text()", FileCfg)


works great !


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 30th, 2009, 1:11 pm 
Offline

Joined: April 14th, 2009, 10:06 am
Posts: 28
(i've post this message in "ask for help" too, dont know exactly where is the right place)

if i have this xml

Code:
<data>
   <a id="a1"></a>
   <a id="a2">
       <b id="b1"></b>
       <b id="b2"></b>
   </a>
   <a id="a3"></a>
</data>


and i want to return the id of the "a" element which has a b child with id = b1

i use..

Code:
/data/a[b/@id = 'b1']/@id/text()   -->returns ai,a2,a3

/data/a[./b/@id = 'b1']/@id/text()   -->returns b1,b2



¿am i doing something wrong or it is a bug?[/code]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 8th, 2009, 5:33 pm 
Hi folks,

any chance to retrieve the weather data with xpath from Google Weather? The XML-File looks like this:

Code:
<xml_api_reply version="1">
<weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0">
<forecast_information>
<city data="Paris, IDF"/>
<postal_code data="Paris"/>
<latitude_e6 data=""/>
<longitude_e6 data=""/>
<forecast_date data="2009-07-08"/>
<current_date_time data="2009-07-08 16:17:27 +0000"/>
<unit_system data="SI"/>
</forecast_information>
<current_conditions>
<condition data="Teils bewölkt"/>
<temp_f data="64"/>
<temp_c data="18"/>
<humidity data="Feuchtigkeit: 77 %"/>
<icon data="/ig/images/weather/partly_cloudy.gif"/>
<wind_condition data="Wind: W mit Windgeschwindigkeiten von 11 km/h"/>
</current_conditions>

<forecast_conditions>
<day_of_week data="Mi."/>
<low data="13"/>
<high data="20"/>
<icon data="/ig/images/weather/partly_cloudy.gif"/>
<condition data="Teils bewölkt"/>
</forecast_conditions>

<forecast_conditions>
<day_of_week data="Do."/>
<low data="12"/>
<high data="22"/>
<icon data="/ig/images/weather/partly_cloudy.gif"/>
<condition data="Teils bewölkt"/>
</forecast_conditions>

<forecast_conditions>
<day_of_week data="Fr."/>
<low data="12"/>
<high data="22"/>
<icon data="/ig/images/weather/partly_cloudy.gif"/>
<condition data="Teils bewölkt"/>
</forecast_conditions>

<forecast_conditions>
<day_of_week data="Sa."/>
<low data="12"/>
<high data="23"/>
<icon data="/ig/images/weather/partly_cloudy.gif"/>
<condition data="Teils bewölkt"/>
</forecast_conditions>
</weather>
</xml_api_reply>


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 8th, 2009, 6:25 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
caby³, Of course (german = natürlich^^)

Code:
xml =
(%
<xml_api_reply version="1">
   <weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0">
      <forecast_information>
         <city data="Paris, IDF"/>
         <postal_code data="Paris"/>
         <latitude_e6 data=""/>
         <longitude_e6 data=""/>
         <forecast_date data="2009-07-08"/>
         <current_date_time data="2009-07-08 16:17:27 +0000"/>
         <unit_system data="SI"/>
      </forecast_information>
      <current_conditions>
         <condition data="Teils bewölkt"/>
         <temp_f data="64"/>
         <temp_c data="18"/>
         <humidity data="Feuchtigkeit: 77 %"/>
         <icon data="/ig/images/weather/partly_cloudy.gif"/>
         <wind_condition data="Wind: W mit Windgeschwindigkeiten von 11 km/h"/>
      </current_conditions>

      <forecast_conditions>
         <day_of_week data="Mi."/>
         <low data="13"/>
         <high data="20"/>
         <icon data="/ig/images/weather/partly_cloudy.gif"/>
         <condition data="Teils bewölkt"/>
      </forecast_conditions>

      <forecast_conditions>
         <day_of_week data="Do."/>
         <low data="12"/>
         <high data="22"/>
         <icon data="/ig/images/weather/partly_cloudy.gif"/>
         <condition data="Teils bewölkt"/>
      </forecast_conditions>

      <forecast_conditions>
         <day_of_week data="Fr."/>
         <low data="12"/>
         <high data="22"/>
         <icon data="/ig/images/weather/partly_cloudy.gif"/>
         <condition data="Teils bewölkt"/>
      </forecast_conditions>

      <forecast_conditions>
         <day_of_week data="Sa."/>
         <low data="12"/>
         <high data="23"/>
         <icon data="/ig/images/weather/partly_cloudy.gif"/>
         <condition data="Teils bewölkt"/>
      </forecast_conditions>
   </weather>
</xml_api_reply>
)

xpath_load(xml)
msgbox % xpath(xml, "/xml_api_reply/weather/current_conditions/condition/@data/text()")
msgbox % xpath(xml, "/xml_api_reply/weather/forecast_conditions[1]/low/@data/text()")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 8th, 2009, 8:03 pm 
@Tuncay:

It works fine. Thx! :)

I thought it would be much difficult.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 8th, 2009, 9:08 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
@diesalher
Code:
xml =
(
<data>
   <a id="a1">
       <b id="b1">hello</b>
       <b id="b2">world</b>
   </a>
   <a id="a2">
       <b id="b3">hallo</b>
       <b id="b4">welt</b>
   </a>
   <a id="a3"></a>
</data>
)
xpath_load(xml)
Loop, % xpath(xml, "/data/a/count()")
{
    s = /data/a[%A_Index%]/b[@id=b3]
    If xpath(xml, s)
    {
        s = /data/a[%A_Index%]/@id
        MsgBox % xpath(xml, s)
    }
}

I could do it only with a loop. This xpath module does not fully support all features of the language (xpath language). My first guess did not work, using the ".." operator in a path for upward.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 9th, 2009, 8:23 am 
Offline

Joined: April 14th, 2009, 10:06 am
Posts: 28
@Tuncay.

Thanks for trying

I tried too with ".." with little exit.

i'm gonna try the loop route but i don't know if it's gonna be fast enough for my needs as my xml could be pretty big.

Thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 9th, 2009, 9:31 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
Quote:
i'm gonna try the loop route but i don't know if it's gonna be fast enough for my needs as my xml could be pretty big.

If you have to operate fast and often on big files with big nodes, then I recommend to set the current node for faster operations. For explanation, see in example:
Code:
xml =
(%
<xml_api_reply version="1">
   <weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0">
      <forecast_information>
         <city data="Paris, IDF"/>
         <postal_code data="Paris"/>
         <latitude_e6 data=""/>
         <longitude_e6 data=""/>
         <forecast_date data="2009-07-08"/>
         <current_date_time data="2009-07-08 16:17:27 +0000"/>
         <unit_system data="SI"/>
      </forecast_information>
      <current_conditions>
         <condition data="Teils bewölkt"/>
         <temp_f data="64"/>
         <temp_c data="18"/>
         <humidity data="Feuchtigkeit: 77 %"/>
         <icon data="/ig/images/weather/partly_cloudy.gif"/>
         <wind_condition data="Wind: W mit Windgeschwindigkeiten von 11 km/h"/>
      </current_conditions>

      <forecast_conditions>
         <day_of_week data="Mi."/>
         <low data="13"/>
         <high data="20"/>
         <icon data="/ig/images/weather/partly_cloudy.gif"/>
         <condition data="Teils bewölkt"/>
      </forecast_conditions>

      <forecast_conditions>
         <day_of_week data="Do."/>
         <low data="12"/>
         <high data="22"/>
         <icon data="/ig/images/weather/partly_cloudy.gif"/>
         <condition data="Teils bewölkt"/>
      </forecast_conditions>

      <forecast_conditions>
         <day_of_week data="Fr."/>
         <low data="12"/>
         <high data="22"/>
         <icon data="/ig/images/weather/partly_cloudy.gif"/>
         <condition data="Teils bewölkt"/>
      </forecast_conditions>

      <forecast_conditions>
         <day_of_week data="Sa."/>
         <low data="12"/>
         <high data="23"/>
         <icon data="/ig/images/weather/partly_cloudy.gif"/>
         <condition data="Teils bewölkt"/>
      </forecast_conditions>
   </weather>
</xml_api_reply>
)

xpath_load(xml)
xml_current := xpath(xml, "/xml_api_reply/weather/current_conditions")
xpath_load(xml_current)
msgbox % xpath(xml_current, "/current_conditions/condition/@data/text()")

xml_fore1 := xpath(xml, "/xml_api_reply/weather/forecast_conditions[1]")
xpath_load(xml_fore1)
msgbox % xpath(xml_fore1, "/forecast_conditions[1]/low/@data/text()")

With xpath_load() you can load an part of an xml file (a node) as a new xml file for operating on it only. In loops and heavy read operations, this can make your script faster. Only thing not to forget is, that write operations goes only to that sub-copies.
... wanted just to mention this method... I am using it successfully...


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 417 posts ]  Go to page Previous  1 ... 24, 25, 26, 27, 28  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: XX0 and 15 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group