 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
jonib
Joined: 09 May 2006 Posts: 75
|
Posted: Wed Jan 21, 2009 8:25 pm Post subject: |
|
|
| bmcclure wrote: | | Are you using v3 of xpath, or the development (v4) version? | I'm using Version 3.13c, I looked at v4 but it seems Load and Save is missing so I'm not sure how to use it, if it is working.
Edit: I could just use StringReplace to change them back before saving.
jonib |
|
| Back to top |
|
 |
mir.shahidul
Joined: 01 Feb 2009 Posts: 1
|
Posted: Sun Feb 01, 2009 8:35 pm Post subject: about DTD |
|
|
I am facing problem writing DTD file.
I want to write DTD syntax of the XML tree like this example: "Marks" is a node and it has two children "Pass" and "Fail". If value of the marks is less than 60 then "Fail" and if marks is greater that 60 then "Pass".
How can write this above scenarion in DTD syntax.
Could anyone please help me?
I will be grateful to u. |
|
| Back to top |
|
 |
bmcclure
Joined: 24 Nov 2007 Posts: 774
|
Posted: Tue Feb 17, 2009 12:31 am Post subject: |
|
|
I have an issue specifying an element that contains brackets in xpath. Should I be escaping something?
My XML has a line like this:
<mod id="EnclaveRadio10[S].esp" />
When trying to get it with:
xpath(XML, "mod[@id="EnclaveRadio10[S].esp"]/@id/text()")
Nothing is returned
However if I get the file by index:
xpath(XML, "mod[1]/@id/text()")
The id is returned properly
My XML file is larger and more complex than this, but none-the-less it works for files without brackets (don't know about other special characters), so I thought I would trim it down for this example.
Update: This continues to be an issue; I can't find a way around it other than converting the brackets to something else, and then converting them back when reading the XML, but since the XMLs can also be made manually by users, that's not really an option. _________________ Ben
My Trac projects
My Wiki
[Broken] - My music |
|
| Back to top |
|
 |
Tuncay
Joined: 07 Nov 2006 Posts: 1886 Location: Germany
|
Posted: Sun Feb 22, 2009 9:30 pm Post subject: |
|
|
I am trieng to upgrade from version 1 of xpath to version 3 and have massive problems. I try to update all old xpath occurrence with new calls.
In old days with xpath 1, I did often this:
| Code: | ConfigDoc := XmlDoc(ConfigFile)
NodeCommands := XPath(ConfigDoc, "/hiscoreRecConfig/commands")
MsgBox % XPath(NodeCommands, "/hiscoreRecConfig/commands/command[@name=mame]/command/text()") |
to enable faster calls, because in this case xpath() does not need to search full document, just the little section which is needed. (this works.)
If I now try this with xpath 3, ill get empty string:
| Code: | xpath_load(ConfigDoc, ConfigFile)
NodeCommands := XPath(ConfigDoc, "/hiscoreRecConfig/commands")
MsgBox % XPath(NodeCommands , "/hiscoreRecConfig/commands/command[@name=mame]/command/text()") | (changed a copy paste error)
it does not work anymore. I want use subsets / parts of a xml file. Why does it not work? On bigger xml files, could this not be a speed up at Loops with high frequently calls of same subset?
Here is the configuration file:
| Code: | <?xml version="1.0" encoding="iso-8859-1"?>
<hiscoreRecConfig>
<options>
<option name="autoSave">0</option>
<option name="exportAutoRun">1</option>
<option name="scoreDelimChar">,</option>
<option name="searchMatchType">InStr</option>
<option name="speedCompareThreshold">5</option>
<option name="listTitleCount">12</option>
<option name="defaultLabelName1">stage</option>
<option name="defaultLabelName2">vehicle</option>
<option name="defaultLabelName3">character</option>
</options>
<users>
<user name="player">Tuncay</user>
<user name="rival">Akira</user>
</users>
<path>
<file name="var">var.ini</file>
<file name="highscores">hiscore.xml</file>
<folder name="backup">backup</folder>
<folder name="programs">bin</folder>
<folder name="cache">cache</folder>
<folder name="export">export</folder>
<folder name="highscores">inp</folder>
<folder name="snap">snap</folder>
<folder name="ico">icons</folder>
</path>
<commands>
<command name="mame">E:\Tuncay\Emulatoren\Mame\Mamepp.exe</command>
<command name="compress">bin\7z.exe a -t7z -mx1</command>
<command name="uncompress">bin\7z.exe e</command>
<command name="scripteditor">C:\Programme\Vim\vim72\gvim.exe</command>
<command name="editor">C:\Programme\Vim\vim72\gvim.exe</command>
</commands>
</hiscoreRecConfig> |
Last edited by Tuncay on Sun Feb 22, 2009 10:10 pm; edited 2 times in total |
|
| Back to top |
|
 |
bmcclure
Joined: 24 Nov 2007 Posts: 774
|
Posted: Sun Feb 22, 2009 10:00 pm Post subject: |
|
|
If I'm not mistaken, your variable NodeCommands only contains the content of the "commands" node. So when you call xpath(NodeCommands, ...) your top-level paths will be your <command> nodes. You shouldn't call the nodes above that, since they aren't in the variable.
Additionally, I don't think you should be using the XmlDoc command with version 3, unless it's a custom command you made. Use xpath_load or xpath_save to load and save a document. _________________ Ben
My Trac projects
My Wiki
[Broken] - My music |
|
| Back to top |
|
 |
Tuncay
Joined: 07 Nov 2006 Posts: 1886 Location: Germany
|
Posted: Sun Feb 22, 2009 10:15 pm Post subject: |
|
|
sorry, I am using xpath_load() with version 3. I have corrected that in example, it was just another typo...
It worked for years you could say, I am not new to xml and xpath.
After that example of me above NodeCommands contains
| Code: | <commands>
<command name="mame">E:\Tuncay\Emulatoren\Mame\Mamepp.exe</command>
<command name="compress">bin\7z.exe a -t7z -mx1</command>
<command name="uncompress">bin\7z.exe e</command>
<command name="scripteditor">C:\Programme\Vim\vim72\gvim.exe</command>
<command name="editor">C:\Programme\Vim\vim72\gvim.exe</command>
</commands> |
Either of following arent working, with or without leading slash:
| Code: | MsgBox % XPath(NodeCommands, "/command[1]")
MsgBox % XPath(NodeCommands, "commands/command[1]") |
... additional note... the xpath expression works fine with given full pathes directly operating on full document. |
|
| Back to top |
|
 |
bmcclure
Joined: 24 Nov 2007 Posts: 774
|
Posted: Sun Feb 22, 2009 10:21 pm Post subject: |
|
|
Hmm, the contents of the variable seem fine, but I'm used to using xpath() with variables returned from xpath_load(), not variables containing raw XML data.
I'm not sure if that's the issue, but if so, I think you might need to pass the string through xpath_load and use the returned value in xpath() instead of the raw xml.
Or you could get the subnodes directly from the xml document, but that would be slower with a large number of them. _________________ Ben
My Trac projects
My Wiki
[Broken] - My music |
|
| Back to top |
|
 |
Tuncay
Joined: 07 Nov 2006 Posts: 1886 Location: Germany
|
Posted: Sun Feb 22, 2009 10:31 pm Post subject: |
|
|
I tried xpath_load() on subsets also, but it wont work. In documentation (which is outdated) stands it would accept strings directly.
Seems this to be a bug? |
|
| Back to top |
|
 |
Tuncay
Joined: 07 Nov 2006 Posts: 1886 Location: Germany
|
Posted: Sun Feb 22, 2009 10:38 pm Post subject: |
|
|
| Hey, I think, I found the problem. I did fileappended the subset in a file and opened it with Vim. There is a note, that the end of file marker is missing. xpath seems to be removing it. (problem continues) |
|
| Back to top |
|
 |
Tuncay
Joined: 07 Nov 2006 Posts: 1886 Location: Germany
|
Posted: Mon Feb 23, 2009 6:55 pm Post subject: |
|
|
| Please help, what can I do? |
|
| Back to top |
|
 |
bmcclure
Joined: 24 Nov 2007 Posts: 774
|
Posted: Mon Feb 23, 2009 8:38 pm Post subject: |
|
|
I've been trying to get some help with the bug I found a few posts back, too; it seems Titan is taking a (well-deserved) break
Hopefully he or someone else is able to assist with this soon, however! _________________ Ben
My Trac projects
My Wiki
[Broken] - My music |
|
| Back to top |
|
 |
tristantzara
Joined: 27 Feb 2009 Posts: 2 Location: Barcelona
|
Posted: Fri Feb 27, 2009 1:59 am Post subject: errors all the time, sorry i'm newie |
|
|
My english is very limitated.
Error: Call to nonexistent function.
I try to learn the Xpath tips, but all the time the same error.
i place de xpath.ahk in the same folder of the script that i would run.
what is the procedure to install xpath library?
i'm sure it's a simple thing.
i use the samples in the post to train, and anything run.
Thanks for all. |
|
| Back to top |
|
 |
bmcclure
Joined: 24 Nov 2007 Posts: 774
|
Posted: Fri Feb 27, 2009 2:35 am Post subject: |
|
|
One of three ways:
Put xpath.ahk in your My Documents\AutoHotKey\lib\ folder
Put xpath.ahk in your AutoHotKey\lib\ folder
Put the following line in your script:
_________________ Ben
My Trac projects
My Wiki
[Broken] - My music |
|
| Back to top |
|
 |
aka_bigred
Joined: 22 Jul 2008 Posts: 7
|
Posted: Sun Mar 01, 2009 5:58 pm Post subject: how to use multiple conditions? |
|
|
How do I use multiple conditions at the same level in Xpath?
This seems to be a valid search condition given this XML testing tool, but Xpath doesn't return the email node as I'd expect. It finds no matches:
theXML
| Code: | <addressBook>
<address>
<firstName>John</firstName>
<surname>Smith</surname>
<email>smithj@world.org</email>
<tel type = "work">234-123-222</tel>
</address>
<address>
<firstName>Alice</firstName>
<surname>Brown</surname>
<email>Alice.Brown@europe.com</email>
<tel type = "home">22-33-444</tel>
<tel type = "work">11-43-222</tel>
</address>
<address>
<firstName>George</firstName>
<surname>White</surname>
<email>gw@rock.com</email>
</address>
</addressBook>
|
| Code: |
xpath_load( theXML )
MsgBox, % xpath_save(theXML) ;
msgbox, % xpath(theXML, "/*/address[firstName=John][surname=Smith]/email/text()")
|
using the exact same XML and Xpath (with double quotes of course), it works with this testing tool:
http://www.zvon.org:9001/saxon/cgi-bin/XLab/XML/addressbook.html?stylesheetFile=XSLT/xpath.xslt&lang=eng
What is the syntax for using multiple conditions on multiple nodes at the same level?
FYI - I'm using Xpath Version 3.13c |
|
| Back to top |
|
 |
Thalon
Joined: 12 Jul 2005 Posts: 633
|
Posted: Mon Mar 16, 2009 10:33 pm Post subject: |
|
|
Hey guys! Long time no see
I've a little problem with XML now.
Isn't it possible to create new nodes with values?
I've a saving-routine this way: | Code: | xpath(XMLDoc, "/files/file[@name='" Programmname "']/Sprache/text()", Sprachen)
xpath(XMLDoc, "/files/file[@name='" Programmname "']/OS/text()", Operatingsystem)
xpath(XMLDoc, "/files/file[@name='" Programmname "']/Bewertung/text()", Bewertung)
xpath_save(XMLDoc, XMLFile) |
But it does only change existing entries and does not create new nodes?
Background:
I'm trying to edit and fill a XML-File with data. The structure is:
| Code: | <?xml version="1.0" encoding="iso-8859-1"?>
<files>
<file name="Test1" hide="1">
<Sprache>DEat</Sprache>
<OS>Win</OS>
</file>
<file name="Test2" hide="0">
<Bewertung>3</Bewertung>
<Sprache>DEat,ENus,ENuk</Sprache>
</file>
</files> | I've no problems with creating attributes (like "hide" above), and I've no problem changing "OS" for "Test1", but I'm not able to add "OS" for "Test2"
This would be a real problem, because most of the items don't have all nodes (like "OS" or "Bewertung")
I hope I haven't missed some limitation and I'm only too stupid for this
If it isn't that easy I'll create a working example.. (my actual test-code has more than 500 lines of code ^^)
Thanks,
Thalon
Edit:
And a little additional question:
How is it possible to save several equal named elements like | Code: | <file>
<Sprache>DEat</Sprache>
<Sprache>ENus</Sprache>
<Sprache>ENuk</Sprache>
<Sprache>fr</Sprache>
<Sprache>de</Sprache>
</file> | ? _________________ AHK-Icon-Changer
AHK-IRC
deutsches Forum |
|
| 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
|