 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Oberon
Joined: 18 Feb 2008 Posts: 458
|
Posted: Fri Feb 22, 2008 2:27 pm Post subject: Re: back to school! |
|
|
| supergrass wrote: | | 1) For some reason I get nothing returned even if I hard code a Book eg: ... "/Book/Gen/text()" | XML is case-sensitive so you need to use /book/Gen/text() since your file starts with <book>.
| supergrass wrote: | | 2) I get an error with .Book. part "The variable name contains an illegal character ".Book."" | The docs says "there should be at least one space on each side of the period" for concatenation so you should use " . Book . " |
|
| Back to top |
|
 |
supergrass
Joined: 21 Feb 2007 Posts: 29 Location: Australia
|
Posted: Mon Feb 25, 2008 12:10 pm Post subject: solved - thanks oberon |
|
|
I think I will add some extra entries for lower case abbreviations as well.
Thanks for the advice |
|
| Back to top |
|
 |
Traderhut Guest
|
Posted: Wed Feb 27, 2008 9:05 pm Post subject: Bug in documentation... xpath.html |
|
|
Hi,
Your example script is wrong, and drove me nuts figuring it out.
New script based on what you wrote:
| Code: | #Include xpath.ahk ; include functions
; creating documents:
xpath_load(feed)
xpath(feed, "/rss[+1]/@version", "2.0") ; create 'rss' node with attribute 'version'
xpath(feed, "/rss/channel[+1]/title[+1]", "second") ; rss > channel > title
xpath(feed, "/rss/channel/title[-1]", "first") ; '-1' puts this node before the last
xpath_save(feed,"test.xml") ; write XML |
Note that xpath takes feed as the first param, and test.xml as the 2nd one. When I ran your example (which was a pain to copy and paste out of explorer by the way) it gave me multiple errors.. Complaining that you had to have a byRef param to the xpath_save... And I figured out that I needed to call xpath_load() at the first (maybe not, as I finally got the end to work) and that I needed the #Include...
However, it seems to have created a file.. However, is this right??
| Code: | <?xml version="1.0" encoding="iso-8859-1"?>
<rss 2.0>
<channel>firstsecond</channel>
</rss> |
Seems like it should have been <rss version=2.0>
And the <channel>firstsecond</channel> seems messed up too...
What am I missing here?
-Chert
www.traderhut.com |
|
| Back to top |
|
 |
Oberon
Joined: 18 Feb 2008 Posts: 458
|
Posted: Wed Feb 27, 2008 9:14 pm Post subject: |
|
|
| When I put /text() after every xpath it worked for me. I guess the examples in the documentation was copied (without testing) from the v2 branch in which the text function is implicit. I don't understand what you mean with the ByRef error though, because 'feed' is a variable. |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2605 Location: Australia, Qld
|
Posted: Wed Feb 27, 2008 10:01 pm Post subject: Re: Bug in documentation... xpath.html |
|
|
| Traderhut wrote: | | and that I needed the #Include... | Read up on Libraries of Functions. #Include is not necessary if you put the script in the right place. |
|
| Back to top |
|
 |
Traderhut Guest
|
Posted: Thu Feb 28, 2008 12:15 am Post subject: Thanks, got it now! + Info on the problem with the example. |
|
|
| Oberon wrote: | | When I put /text() after every xpath it worked for me. I guess the examples in the documentation was copied (without testing) from the v2 branch in which the text function is implicit. I don't understand what you mean with the ByRef error though, because 'feed' is a variable. |
I changed the code from the example:
| Code: | | xpath_save(feed,"test.xml") ; write XML |
which gives the error, to:
| Code: | | xpath_save("test.xml",feed) ; write XML |
which does not.
So, if I understand you right, the code should be:
| Code: | xpath_load(feed)
xpath(feed, "/rss[+1]/@version/text()", "2.0") ; create 'rss' node with attribute 'version'
xpath(feed, "/rss/channel[+1]/title[+1]/text()", "second") ; rss > channel > title
xpath(feed, "/rss/channel/title[-1]/text()", "first") ; '-1' puts this node before the last
xpath_save(feed,"test.xml") ; write XML |
(Just tested this, it gives a valid xml file)
Thanks for the help, this is pretty cool.. Maybe I can automate a bunch of the busy work that gets done around here.... (a 5 second code change takes 4 hours of work to get it pushed into Regression testing due to the documentation of the change... I.E. I changed for (I=0; I < 5; I++) to for (I=0; I < 10; I++) to change the number of years displayed in a combo box from now+5 years to now+10.. Expected impact: zero.. Oh, well...
Thanks,
-Chert
PS: (That isn't a problem a Traderhut, Traderhut.com is my home system, but it's a problem where I work to pay for my toys...) |
|
| Back to top |
|
 |
Guest
|
Posted: Tue Mar 04, 2008 4:45 am Post subject: Adding task in Bonsai Outliner Using Xpath |
|
|
I have been trying to add in the task in an exisiting Bonsai outline task using Xpath.
Following is the code
| Code: | <items xml:space="preserve">
<item id="1702126217" type="simple" custom1="31" create-date="15 May 2007 05:45" last-modified="04 Mar 2008 11:35" pos-hint="2147483648" modified="#40">
<text>Processing</text>
<items>
<item id="1702126249" type="todo" create-date="04 Mar 2008 09:17" last-modified="04 Mar 2008 11:35" percent-complete="0" pos-hint="0" modified="#240">
<text>Call Fred about the book</text>
</item>
</items>
</item>
</items>
|
In the first place I dont know whether this format of XML is fine to use with xpath.
Following is the code I used in autohotkey to retrieve the text
| Code: | #Include XPath.ahk
sXMLFullPath =xpath_load("GTD-Inbox.OTL")
toutline= % xpath(sXMLFullPath, "/items/item/text()")
msgbox %toutline%
|
Whenever I run this program I get a blank message box.
Thank you very much for your help. |
|
| Back to top |
|
 |
Oberon
Joined: 18 Feb 2008 Posts: 458
|
Posted: Tue Mar 04, 2008 8:53 am Post subject: |
|
|
| You forgot to use the expression-type assignment sXMLFullPath := xpath_load |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Mar 05, 2008 3:55 am Post subject: Still it doenst work |
|
|
Hi Oberon, thanks for your immediate reply. I changed it to the expression but it did not work.
In the first place can anyone tell me whether the xml format I have mentioned in the earlier post will work with xpath. |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2605 Location: Australia, Qld
|
Posted: Wed Mar 05, 2008 7:12 am Post subject: |
|
|
Your usage is incorrect. According to the manual, the return value is "False if there was an error in loading the document, true otherwise." The first parameter should be the variable you want to load the XML into, and the second should be the name of the file to load from.
| Code: | xpath_load(xml, "GTD-Inbox.OTL")
toutline := xpath(xml, "/items/item/text()")
msgbox %toutline% |
If the second parameter is omitted, the first parameter is converted from XML into a format xpath can use.
| Code: | xml =
(
<items xml:space="preserve">
<item id="1702126217" type="simple" custom1="31" create-date="15 May 2007 05:45" last-modified="04 Mar 2008 11:35" pos-hint="2147483648" modified="#40">
<text>Processing</text>
<items>
<item id="1702126249" type="todo" create-date="04 Mar 2008 09:17" last-modified="04 Mar 2008 11:35" percent-complete="0" pos-hint="0" modified="#240">
<text>Call Fred about the book</text>
</item>
</items>
</item>
</items>
)
xpath_load(xml)
toutline := xpath(xml, "/items/item/text()")
msgbox %toutline% |
|
|
| Back to top |
|
 |
Guest
|
Posted: Fri Mar 07, 2008 2:16 am Post subject: Thanks for Highlighting the error |
|
|
Thank you lexiKos, that worked for me. But I have another problem, when the xml file starts with the tag <bonsai-outline> the script display only an empty message box.
| Code: | <bonsai-outline>
<items>
<item>
<text></text>
</item>
<item>
<text></text>
</item>
</items>
</bonsai-outline>
|
But when I change bonsai-outline tag to bonsaioutline without the hypen then the script displays the value of the text tag.
Titan, can you please let me know whether this is a problem in the script or by default the tags should not have an hypen.
Thank you very much. |
|
| Back to top |
|
 |
SecurityAnalysis Guest
|
Posted: Mon Apr 28, 2008 8:24 pm Post subject: |
|
|
This line works in 3.10rc3 but it doesn't work with the newest version 3.13. What things have changed in the syntax since then?
| Code: |
DealtPlayersNames := xpath(hand, "/HandDetails/DetailLines/DetailLine[@Action='Seat'][@PlayerName]/@PlayerName/text()")
|
|
|
| Back to top |
|
 |
Titanz Guest
|
Posted: Mon Apr 28, 2008 9:12 pm Post subject: |
|
|
| I haven't modified xpath in months. Could you post your XML file or at least a sample of it which fails to produce the desired result? Also can you confirm that you have the latest version, 3.13c? |
|
| Back to top |
|
 |
SecurityAnalysis Guest
|
Posted: Mon Apr 28, 2008 10:04 pm Post subject: |
|
|
Sure. Here is a code example. This message box shows names with XPath 3.10rc3 but shows blank with 3.13. Thanks for helping and also for being so quick!
| 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
hand=
(
<HandDetails SiteName="Everest" GameNumber="3105833541" PokerGameType="NLHoldem" BigBlindAmount="2" SmallBlindAmount="1" Ante="0" HandDate="Apr 13,2008 22:08:17" TableName="Suva21" RealMoney="True" IsTourney="False" TourneyBuyin="0" TourneyEntryFee="0" TourneyNumber="" ButtonSeat="3">
<DetailLines>
<DetailLine PlayerName="waz_Q6" Action="Seat" SeatNumber="1" StackSize="375.65"/>
<DetailLine PlayerName="CptFranklin" Action="Seat" SeatNumber="2" StackSize="180.85"/>
<DetailLine PlayerName="ergi" Action="Seat" SeatNumber="3" StackSize="27"/>
<DetailLine PlayerName="yznogood" Action="Seat" SeatNumber="4" StackSize="205.3"/>
<DetailLine PlayerName="220373" Action="Seat" SeatNumber="5" StackSize="190.35"/>
<DetailLine PlayerName="PkrTxsRngr" Action="Seat" SeatNumber="6" StackSize="211.5"/>
<DetailLine PlayerName="yznogood" Action="PostedSB" Amount="1"/>
<DetailLine PlayerName="220373" Action="PostedBB" Amount="2"/>
<DetailLine PlayerName="ergi" Action="HeroCards" Cards="AdTc" />
<DetailLine Action="DealingDownCards" />
<DetailLine PlayerName="PkrTxsRngr" Action="Folds" />
<DetailLine PlayerName="waz_Q6" Action="Folds" />
<DetailLine PlayerName="CptFranklin" Action="Folds" />
<DetailLine PlayerName="ergi" Action="Raises" Amount="27"/>
<DetailLine PlayerName="yznogood" Action="Calls" Amount="26"/>
<DetailLine PlayerName="220373" Action="Folds" />
<DetailLine PlayerName="yznogood" Action="Shows" Cards="AsTh"/>
<DetailLine PlayerName="ergi" Action="Shows" Cards="AdTc"/>
<DetailLine Action="DealingFlop" Cards="Kc8d9h" />
<DetailLine Action="DealingTurn" Cards="Qd" />
<DetailLine Action="DealingRiver" Cards="6s" />
<DetailLine PlayerName="ergi" Action="Wins" Amount="26.6"/>
<DetailLine PlayerName="yznogood" Action="Wins" Amount="26.6"/>
</DetailLines></HandDetails>
)
xpath_load(hand, handvar)
DealtPlayersNames := xpath(hand, "/HandDetails/DetailLines/DetailLine[@Action='Seat'][@PlayerName]/@PlayerName/text()")
MsgBox, % DealtPlayersNames
|
|
|
| Back to top |
|
 |
Titanz Guest
|
Posted: Mon Apr 28, 2008 10:41 pm Post subject: |
|
|
| Removing [@PlayerName] in your expression worked for me. I don't know why this is, presumably because the attribute in question is part of the request which causes conflicts somehow - short cut optimisation perhaps? Regardless it is a bug as it breaks standard so I will have to fix it in future. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|