https://wiki.kolmafia.us/index.php?title=Xpath&feed=atom&action=history
Xpath - Revision history
2024-03-28T21:42:25Z
Revision history for this page on the wiki
MediaWiki 1.35.0
https://wiki.kolmafia.us/index.php?title=Xpath&diff=8472&oldid=prev
imported>Ulti at 13:43, 30 April 2015
2015-04-30T13:43:40Z
<p></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 13:43, 30 April 2015</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l68" >Line 68:</td>
<td colspan="2" class="diff-lineno">Line 68:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>}}</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>}}</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>[[<del class="diffchange diffchange-inline">Category:Ash Functions|</del>Category:String Handling Routines]]</div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>[[Category:String Handling Routines]]</div></td></tr>
</table>
imported>Ulti
https://wiki.kolmafia.us/index.php?title=Xpath&diff=8471&oldid=prev
imported>Ulti: Created page with "{{ #vardefine:name|xpath}}{{ #vardefine:return_type|string[int]}}{{ #vardefine:aggregate|yes}}{{ FunctionPage| name={{#var:name}}| function1={{Function| name={{#var:name}}|..."
2015-04-30T13:42:21Z
<p>Created page with "{{ #vardefine:name|xpath}}{{ #vardefine:return_type|string[int]}}{{ #vardefine:aggregate|yes}}{{ FunctionPage| name={{#var:name}}| function1={{Function| name={{#var:name}}|..."</p>
<p><b>New page</b></p><div>{{<br />
#vardefine:name|xpath}}{{<br />
#vardefine:return_type|string[int]}}{{<br />
#vardefine:aggregate|yes}}{{<br />
<br />
FunctionPage|<br />
name={{#var:name}}|<br />
<br />
function1={{Function|<br />
name={{#var:name}}|<br />
aggregate={{#var:aggregate}}|<br />
return_type={{#var:return_type}}|<br />
return_also={{#var:return_also}}|<br />
parameter1={{Param|string|htmldocument}}|<br />
parameter2={{Param|string|xpathselector}}|<br />
p1desc={{Pspan|htmldocument}} is a string representing an html document such as that returned from visit_url|<br />
p2desc={{Pspan|xpathselector}} is a standard xpath selector for selecting nodes in the document|<br />
}}|<br />
<br />
function_description=This function returns an array of strings, for efficiency purposes, not a map, representing the node(s) which xpath has selected for you in the html document. Unlike a map, arrays will encounter an "out of bounds" exception when attempting to add new elements to it, do note the difference. This function will return an empty array if no nodes match the selector. In the event the selector uses invalid syntax, this function will error with "invalid xpath expression"|<br />
<br />
code1={{CodeSample|<br />
title=Code Sample|<br />
description=The following code, if you are stuck in a choice adventure, will output the options of that choice adventure.|<br />
code=<syntaxhighlight><br />
string[int] textOptions;<br />
string[int] valueOptions;<br />
string[int] choiceAdventureNumber;<br />
string[int] choiceAdventureName;<br />
string page=visit_url('charsheet.php');<br />
textOptions=xpath(page,'//form[@action="choice.php"]//input[@type="submit"]/@value');<br />
valueOptions=xpath(page,'//form[@action="choice.php"]//input[@type="hidden"][@name="option"]/@value');<br />
choiceAdventureNumber=xpath(page,'//form[@action="choice.php"]//input[@type="hidden"][@name="whichchoice"]/@value');<br />
choiceAdventureName=xpath(page,'//tr/td/b/text()');<br />
if(count(textOptions)==0 || count(valueOptions)==0 || count(choiceAdventureNumber)==0)<br />
{<br />
print('not in a choice adventure');<br />
}else{<br />
string choiceAdvName;<br />
string choiceAdvNum=choiceAdventureNumber[0];<br />
if(count(choiceAdventureName)==0)<br />
{<br />
choiceAdvName='unnamed choice adventure';<br />
}else{<br />
choiceAdvName=choiceAdventureName[0];<br />
}<br />
print('choice adventure #'+choiceAdvNum+':'+choiceAdvName);<br />
for x from 0 to count(valueOptions)-1<br />
{<br />
print('option '+valueOptions[x]+':'+textOptions[x]);<br />
}<br />
}<br />
</syntaxhighlight><br />
|moreinfo=<br />
For example, if you used "intriguing puzzle box" from your inventory and ran the above script, you'd see the following output:<br />
<pre>choice adventure #525:Fiddling with a Puzzle<br />
option 1:Push the left face.<br />
option 2:Turn the right face clockwise.<br />
option 3:Turn the rear face counterclockwise.<br />
option 4:Push the right face.<br />
option 5:Turn the right face counterclockwise.<br />
option 6:Turn the left face counterclockwise.<br />
option 7:Stop messing with this dang puzzle.</pre><br />
}}|<br />
<br />
<br />
see_also={{SeeAlso|visit_url}}|<br />
}}<br />
<br />
[[Category:Ash Functions|Category:String Handling Routines]]</div>
imported>Ulti