AutoHotkey Community

It is currently May 25th, 2012, 1:53 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, 2, 3, 4, 5, 6 ... 28  Next
Author Message
 Post subject:
PostPosted: August 3rd, 2007, 8:58 pm 
Ok, I am not fully understanding something, so maybe you can help. I am attempting to get data out of a Form file (*.XFT), which is implemented in XML:

This is not the begining of the file, the file is very big, but what I am interested in, is getting the HeightInChars, and WidthInChars from the given field.
Code:
    <field name="SCHEDULE" y="191.56mm" x="25.4mm" w="170.39mm" h="11.38mm">
     <value>
      <exData/>
     </value>
     <ui>
      <textEdit>
       <extras type="application/x-active-x">
        <integer name="WantReturns">-1</integer>
        <integer name="Occurrence">1</integer>
        <text name="MapIndex">00033</text>
        <text name="EXTENDED_CodeBase">RichEdit.dll</text>
        <integer name="LabelForeColor"/>
        <integer name="SystemLabelForeColor">-2147483640</integer>
        <integer name="LabelBackColor">16777215</integer>
        <integer name="SystemLabelBackColor">-2147483643</integer>
        <integer name="SystemInactiveBackColor">-2147483633</integer>
        <integer name="ScrollLabel"/>
        <integer name="BackColor">16777215</integer>
        <integer name="SystemBackColor">-2147483643</integer>
        <integer name="PrintBackColor">16777215</integer>
        <text name="Tab">1270;Left</text>
        <float name="RightIndent"/>
        <float name="SpaceBefore"/>
        <float name="SpaceAfter"/>
        <integer name="LineSpacing">4</integer>
        <float name="LineSpacingPoints">12.5</float>
        <float name="SpecialIndentBy"/>
        <text name="SpecialIndent">(none)</text>
        <integer name="HeightInChars">2</integer>
        <integer name="WidthInChars">79</integer>
        <integer name="SaveBorderPlacement">-1</integer>
        <text name="CalcEngine">Default</text>
        <integer name="BorderPlacement">3</integer>
        <integer name="StartingColor">13160660</integer>
        <integer name="MaxChars">240</integer>
       </extras>
      </textEdit>
     </ui>
     <caption>
      <font size="9.75pt" typeface="Courier"/>
     </caption>
     <font size="9.75pt" typeface="Courier">
      <fill>
       <color value="0,0,0"/>
      </fill>
     </font>
     <calculate override="warning"/>
     <border hand="right">
      <edge thickness="0.26mm" stroke="lowered">
       <color value="0,0,0"/>
      </edge>
      <fill>
       <solid/>
       <color value="212,208,200"/>
      </fill>
     </border>
     <margin topInset="0.26mm" rightInset="0.26mm" leftInset="0.26mm" bottomInset="0.26mm"/>
    </field>


I am getting the field name in my ListView correctly, I just can't seem to get any information based on attribute values, when I try other variations, it returns the whole field node.

The portion of my *.ahk script that matters looks like this:
Code:
xml := XmlDoc(XFTFile) ; load the xft file
fields := XPath(xml, "/xfa/template/subform/area/field")
Loop, Parse, fields, `, ; the delimiter is always a comma
   LV_Add(XPath(fields, "/xfa/template/subform/area/field"[ . A_Index . "]/@name[1]/text()"))
StringSplit, fields_, fields, `, ; the variable 'fields_0' contains the number of selected elements
LV_Delete()
Loop, %fields_0% {
;This gets the field name and works correctly
    LV_Add("",XPath(fields_%A_Index%, "field/@name[1]/text()"))

;This is supposed to get the HeightInChars, and won't work
    LV_Add("",XPath(fields_%A_Index%, "field/ui/textEdit/extras/integer[@name='HeightInChars']/text()"))


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2007, 10:23 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
You made a few mistakes - firstly you should only operate on XmlDoc() vars and the second parameter in LV_Add() shows the values. Here's what it should look like:

Code:
xml := XmlDoc(XFTFile) ; load the xft file
fields := XPath(xml, "/xfa/template/subform/area/field") ; use this value to parse each field set

Loop, Parse, fields, `, ; for each:
   LV_Add("", XPath(xml, "/xfa/template/subform/area/field[" . A_Index . "]/@name/text()")) ; get field name

LV_Add("", XPath(xml, "/xfa/template/subform/area/field/@name/text()")) ; get all field names as a comma seperated list
LV_Add("", XPath(xml, "/xfa/template/subform/area/field/ui/textEdit/extras/integer[@name=HeightInChars]/text()")) ; get all HeightInChars integer values

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2007, 3:58 pm 
Offline

Joined: May 11th, 2007, 1:08 pm
Posts: 26
I have a basic query regarding XML.

I want to use a xml file to store my hotkeys, and then to load them into a Listview. I created an xml file, but I'n not quite sure that this is a valid xml file, could you please have a look into it, and advise if possibe?

Thank you in advance! :)

Here is one item and the leading part of my xml file.
Code:
<?xml version="1.0" encoding="UTF-8"?>

<channel>
<title>REDFOG hotkey list</title>
<description>Hotkey list for REDFOG</description>
<author>Mate Gulyas</author>
</end>

<item>
<name>!mail</name>
<description>Standard mail reply form</description>
</item>

_________________
dA Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2007, 4:04 pm 
Offline

Joined: October 10th, 2005, 10:44 am
Posts: 299
Location: Germany
Doesn't look quite right, Avalon; you're missing a root element, and the </end> tag should probably be </channel>:
Code:
<?xml version="1.0" encoding="UTF-8" ?>

<root>

<channel>
    <title>REDFOG hotkey list</title>
    <description>Hotkey list for REDFOG</description>
    <author>Mate Gulyas</author>
</channel>

<item>
    <name>!mail</name>
    <description>Standard mail reply form</description>
</item>

</root>

There should also be a well-formedness checker out there (Tidy?) - although proper validation requires a DTD or Schema.

_________________
Improving my world, one script at a time.
Join the AutoHotkey IRC channel: irc.freenode.net #autohotkey


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2007, 5:22 pm 
Offline

Joined: May 11th, 2007, 1:08 pm
Posts: 26
Ace_NoOne wrote:
There should also be a well-formedness checker out there (Tidy?) - although proper validation requires a DTD or Schema.


Thanks, I reformatted my XML file, but my code is still not working.

Here is my XML file:
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<channel>
    <title>Hotkey list</title>
    <description>Hotkey list for SC script</description>
    <author>SG</author>
</channel>

<item>
<name>!mail</naquotme>
<description>Standard mail reply form</description>
<scope>Lotus Notes</scope>
</item>

<item>
<name>!scont</name>
<description>Subject of Contact Exception email</description>
<scope>Lotus Notes</scope>
</item>

<item>
<name>!cont</name>
<description>Body of Contact Exception email</description>
<scope>Lotus Notes</scope>
</item>

<item>
<name>mll</name>
<description>Cleans up ICT Incident report mail</description>
<scope></scope>
</item>

<item>
<name>pwmll</name>
<description>Cleans up ICT password reset mail</description>
<scope>global</scope>
</item>

<item>
<name>!regards</name>
<description>Best regards, [Your name]</description>
<scope>Lotus Notes</scope>
</item>

<item>
<name>tel</name>
<description>telephone number</description>
<scope>global</scope>
</item>

<item>
<name>Pw</name>
<description>Password</description>
<scope></scope>
</item>

<item>
<name>pw</name>
<description>password</description>
<scope></scope>
</item>

</root>


Any idea how I should parse this whole file into a ListView?
I'm thinking something like this: (it still misses the exit condition of the Loop, and I have a guess that my XML reading part is a total deadend. :(
Code:
Loop
{
xml := XmlDoc("hotkeys.xml")
hotkeys := XPath(xml, "/channel/item[%A_Index%]/name/text()")
description := XPath(xml, "/channel/item[%A_Index%]/description/text()")
scope := XPath(xml, "/channel/item[%A_Index%]/scope/text()")
LV_Add(,%hotkeys%,%description%,%scope%)
}

_________________
dA Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2007, 5:46 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
There are a few errors in your script, see FAQ: When exactly are variable names enclosed in percent signs?

Here is a working example:

Code:
#Include XPath.ahk

Gui, Add, ListView, w400 r10, Hotkeys|Description|Scope
Gui, Show, , Example

xml := XmlDoc("hotkeys.xml") ; this only needs to be loaded once

Loop
{
   If XPath(xml, "/root/item[" . A_Index . "]") = ""
      Break
   hotkeys := XPath(xml, "/root/item[" . A_Index . "]/name/text()")
   description := XPath(xml, "/root/item[" . A_Index . "]/description/text()")
   scope := XPath(xml, "/root/item[" . A_Index . "]/scope/text()")
   LV_Add("", hotkeys, description, scope)
}

Return

GuiClose:
ExitApp


There there is also a typo in your XML, </naquotme> should be </name>.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2007, 11:29 pm 
Offline

Joined: May 11th, 2007, 1:08 pm
Posts: 26
Titan wrote:
There are a few errors in your script, see FAQ:

Yeah, now i can see how many errors I had. :S I'm very new to this progamming thing, I usually make some very lame mistakes. :)

I could manage to get to a working version, however I had to use the simple GUI, as with Gui, 2: wasn't working. So now my simple GUI is the one which uses the ListView, and the previous is the second ( GUI, 2: ).

Thanks for the help anyway, I will try to do more complicated XMLs, I find it very useful. :)

_________________
dA Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2007, 6:27 pm 
Online
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
I have a trouble with a XML file that looks like this
Code:
<docu number="2">
     <function name="add">
        <syntax>number1, number2[, number3=0]</syntax>
    </function>
    <function name="pow">
        <syntax>base, exponent</syntax>
    </function>
</docu>


And I want to read each <function> tag.
My code:
Code:
xmlbase := XmlDoc("test.xml")
nfuncs := XPath(xmlbase, "/docu/@number/text()")
Loop, %nfuncs%
{
   funcname := XPath(xmlbase, "/docu/function[" A_Index "]/@name/text()") ; Get function's name
   syntax := XPath(xmlbase, "/docu/function[" A_Index "]/syntax/text()")
   MsgBox %funcname%`n%syntax%
}


I get MsgBoxed two times: one with add,pow and other with nothing. Can you tell me what's wrong in my code?

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2007, 7:32 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
It works fine for me. You should use StringReplace, syntax, syntax, ,, `,, All before the message box to unescape the syntax variable. Are you sure you have the latest version of AutoHotkey and XPath.ahk?

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2007, 9:32 pm 
Online
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8649
Location: Salem, MA
Titan,

can you rename the XMLDoc function to XPath_XMLDoc, (or add a single line wrapper to do the same)?

It will then be StdLib compliant when called XPath.ahk

Thanks

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2007, 9:44 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
I'm not too keen on prefixes but I'll consider it for the next version.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2007, 10:14 pm 
Online
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
@Titan:

I'm using latest version of AutoHotkey and XPath.
Oh, I forget to say that the XML file is auto-generated when I read and parse a file (and I don't use XmlDoc, so the XML file aren't preprocessed), so the commas are the trouble. Well, problem solved! Thanks!

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2007, 1:55 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
I'm glad you got it working.

By the way xpath 2.0 will be out soon and I've published the documentation for it (best viewed in Firefox). This version parses nodes a lot faster than msxml3 when using the current COM wrappers. Hopefully if and when these wrappers are improved I plan to write an XML DOM set of functions complete with XSLT.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 29th, 2007, 12:15 am 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
xpath 2.0 alpha released w00t!
Users are requested to test scripts for compatibility and contact me if they notice any bugs etc.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 29th, 2007, 12:35 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Titan wrote:
This version parses nodes a lot faster than msxml3 when using the current COM wrappers.

You're really obsessed with the speed. Anyway, I don't think the COM could compete with the functions here no matter how much optimized is the code. Even neither with the VTBL interface (:why didn't you try VTBL anyway. You said you were gonna try VTBL). Why? It always have to convert the (ANSI) string to Unicode string, then, have to allocate and fill another buffer via SysAllocString.

Just test it if you're concerned after optimizing Invoke() as possible as you can.


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, 2, 3, 4, 5, 6 ... 28  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 22 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