AutoHotkey Community

It is currently May 26th, 2012, 9:12 am

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 ... 18, 19, 20, 21, 22, 23, 24 ... 28  Next
Author Message
 Post subject:
PostPosted: July 15th, 2008, 1:28 am 
Offline

Joined: April 28th, 2008, 2:55 pm
Posts: 48
Thanks for the reply.

I was hoping to insert the block without having to iterate through the xml to be inserted (meaning, I would just like to insert the raw XML into the current document).

Another question, I noticed that the performance of the code I am using to convert data into XML degrades according to the size of the document. Is there a more efficient way to do the following:

Code:
syslist_ConvertToXML(listName, ByRef xml) {

   list := syslist_Get(listName)
                                                 "
   xml := ""
   xpath(xml, "/" . listName . "[+1]/@version", "2.0")

   loop,Parse,list,`n
   {
      fieldIndex := 1
      fields := A_LoopField
      type := removeValue(fields, "type")

      removeValue(fields, "listName")
      loop
      {
         StringGetPos, epos, fields, :
         if epos = -1
            break
         name := SubStr(fields, 2, epos-1)
         xvalue := removeValue(fields, name)
StartTime := A_TickCount
         if (fieldIndex = 1) {
            xpath(xml, "/" . listName . "/" . type . "[+1]/" . name . "[+1]/text()", xvalue)
         } else {
            xpath(xml, "/" . listName . "/" . type . "[last()]/" . name . "[+1]/text()", xvalue)
         }
         
         fieldIndex ++
log("xpath elapsed:" . A_TickCount - StartTime)
      }
   }

   return xml
}


In the beginning of the process, the time elapsed is close to 0. At the end of the process, the time elapsed averages 100 milliseconds. The complete document contains roughly 600 lines.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 15th, 2008, 1:51 am 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
joebodo wrote:
I would just like to insert the raw XML into the current document
It's an undocumented feature but you can do so simply by passing an XML fragment to the set parameter, e.g.:

Code:
xml =
(
<Redstone version="2.0">
  <command>
    <Command>List Add</Command>
    <Callback>list_AddEntry</Callback>
    <name>List Add</name>
  </command>
  <command>
    <Command>List Merge</Command>
    <Callback>list_Merge</Callback>
    <name>List Merge</name>
  </command>
</Redstone>
)

xpath_load(xml)

insertx = <Command>Volume Unmute</Command><Callback>volume_Command</Callback><name>Volume Unmute</name>
xpath(xml, "/Redstone/content[+1]/text()", insertx)

MsgBox, % xpath_save(xml)


joebodo wrote:
I noticed that the performance of the code I am using to convert data into XML degrades according to the size of the document. Is there a more efficient way to do the following
As with SQL there are optimization tricks you can use with xpath (not just for this parser) but I can't say exactly without looking at the rest of your code. What is obvious to me is your repeated use of last(), put a counter variable within if (fieldIndex = 1) { ... } and replace [last()] with "[" . typeIndex . "]". You could also use fragments and insert them into your main XML document as I talked about earlier. I would expect this to be faster by orders of magnitude since the tree would be direct to every name element you add.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 15th, 2008, 8:27 pm 
Offline

Joined: April 28th, 2008, 2:55 pm
Posts: 48
Titan,

I was able to insert the xml fragment into the document (quite fast). But... after inserting in this manner, the document is no longer searchable using the select: keyword. To resolve this issue, I did a xpath save/load to rebuild the xml object.

I've been looking through the thread and cannot find the answer to this problem. Is there a way to list the nodes of a document? I am trying to iterate over the xml fragment and insert the nodes and each name/value into the document. If you need pseudo code to understand this question, let me now.

Sorry for so many questions, but I am trying to replace most of the infrastructure (message passing and metadata management) in my program with XML.

Thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 15th, 2008, 10:18 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
joebodo wrote:
after inserting in this manner, the document is no longer searchable using the select: keyword.
That is because xpath doesn't reparse fragments, hence why this is an undocumented hack. I amended this for xpath4 which I'm hoping to release soon but in the mean time I suggest you stick with adding nodes manually.

joebodo wrote:
Is there a way to list the nodes of a document? I am trying to iterate over the xml fragment and insert the nodes and each name/value into the document. If you need pseudo code to understand this question, let me now.
You can use /* or count() with indexes. If you post some XML I can show an example.

joebodo wrote:
Sorry for so many questions
Don't be, I get free bumps this way ;)

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 16th, 2008, 3:58 am 
Offline

Joined: April 28th, 2008, 2:55 pm
Posts: 48
Need some assistance iterating through XML nodes

Input Document
Code:
<Redstone 2.0>
  <command>
    <Command>List Merge</Command>
    <Callback>list_Merge</Callback>
    <name>List Merge</name>
  </command>
</Redstone>


XML to Insert
Code:
<command>
  <type>command</type>
  <Command>Status Display</Command>
  <Callback>statusbar_Display</Callback>
  <name>Status Display</name>
</command>


Desired Output
Code:
<Redstone 2.0>
  <command>
    <Command>List Merge</Command>
    <Callback>list_Merge</Callback>
    <name>List Merge</name>
  </command>
  <command>
    <type>command</type>
    <Command>Status Display</Command>
    <Callback>statusbar_Display</Callback>
    <name>Status Display</name>
  </command>
</Redstone>


xpath(entry, "/*") returns
Code:
<command><type>command</type><Command>Tooltip Register</Command><Callback>tooltip_Register</Callback><name>Tooltip Register</name></command>


Pseudo-code
Code:
For each node name (maybe not correct terminology)
{
   get value of node
   insert name/value into document
}


Note that I do not know at runtime the node name or values that this method will be processing (therefore, I cannot hard-code in the node names)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 17th, 2008, 3:33 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
I agree this is difficult without proper DOM access, but you can use /*/*/text(), insert and reparse. Stop idleing on IRC and I'll give you some working code :P

xpath4 alpha available at http://www.autohotkey.net/~Titan/repos/xpath4.ahk more details later.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 24th, 2008, 11:07 pm 
Hello,

I am trying something like

Code:
xpath(test_db, "/car_db/cars[company='BMW' and product='850i']/id/text()")


Does anyone have an idea how to get it working?

Many thanks and regards,
Martin


Report this post
Top
  
Reply with quote  
 Post subject: Quick Question....
PostPosted: August 4th, 2008, 10:48 pm 
Offline

Joined: April 8th, 2008, 1:08 am
Posts: 100
Location: Minnesota, USA
I don't know XML at all... but this should be fairly simple, I need to read this file, Record.wme (Windows Media Encoder Settings) and replace the text,

C:\Recording\ScreenRecord1.wmv

with

C:\Recording\ScreenRecord2.wmv

(The script will search for how many screen records were created, and will add 1 to create a new file so none are overwritten, just an example)

Code:
<?xml version="1.0"?>

<WMEncoder major_version="9"
    minor_version="0"
    Name="WMEncoder21912"
    SynchroniesOperation="0" >
    <Description />
    <SourceGroups >
        <SourceGroup Name="ScreenCapture" >
            <Source Type="WMENC_VIDEO" Scheme="screencap" >
                <UserData >
                    <WMENC_STRING Name="WindowTitle" />
                    <WMENC_LONG Name="CaptureWindow" Value="0" />
                    <WMENC_LONG Name="Left" Value="222" />
                    <WMENC_LONG Name="Top" Value="149" />
                    <WMENC_LONG Name="Right" Value="1190" />
                    <WMENC_LONG Name="Bottom" Value="845" />
                    <WMENC_DOUBLE Name="FrameInterval" Value="0.3333" />
                    <WMENC_BOOL Name="FlashRect" Value="no" />
                    <WMENC_BOOL Name="Screen" Value="no" />
                </UserData>

            </Source>

            <EncoderProfile id="Screen Video (CBR)" />
            <UserData >
            </UserData>

        </SourceGroup>

    </SourceGroups>

    <File LocalFileName="C:\Recording\ScreenRecord1.wmv" />    <WMEncoder_Profile id="Screen Video (CBR)" >
    <![CDATA[        <profile version="589824"
             storageformat="1"
             name="Screen Video (CBR)"
             description="">
                   <streamconfig majortype="{73646976-0000-0010-8000-00AA00389B71}"
                   streamnumber="1"
                   streamname="Video Stream"
                   inputname="Video409"
                   bitrate="27000"
                   bufferwindow="-1"
                   reliabletransport="0"
                   decodercomplexity=""
                   rfc1766langid="en-us"
 >
                     <videomediaprops maxkeyframespacing="80000000"
                                     quality="100"/>
             <wmmediatype subtype="{3253534D-0000-0010-8000-00AA00389B71}" 
                   bfixedsizesamples="0"
                   btemporalcompression="1"
                   lsamplesize="0">
       <videoinfoheader dwbitrate="27000"
                        dwbiterrorrate="0"
                        avgtimeperframe="3333333">
        <rcsource left="0"
                  top="0"
                  right="0"
                  bottom="0"/>
        <rctarget left="0"
                  top="0"
                  right="0"
                  bottom="0"/>
            <bitmapinfoheader biwidth="0"
                              biheight="0"
                              biplanes="1"
                              bibitcount="24"
                              bicompression="MSS2"
                              bisizeimage="0"
                              bixpelspermeter="0"
                              biypelspermeter="0"
                              biclrused="0"
                              biclrimportant="0"/>
       </videoinfoheader>
            </wmmediatype>
            </streamconfig>
    </profile>
    ]]>
    </WMEncoder_Profile>

    <UserData >
        <WMENC_LONG Name="Encoding\LocalComplexity" Value="0" />
        <WMENC_LONG Name="Encoding\BroadcastComplexity" Value="0" />
    </UserData>

</WMEncoder>



Help would be appreciated... I'm lost

_________________
-trueski-


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 14th, 2008, 12:19 pm 
Titan wrote:
I agree this is difficult without proper DOM access, but you can use /*/*/text()...

...not that exact test, but when I was trying to Loop via * nodes all I got was more unparsed XML...I need to Loop, Parse, XML...& then get A_LoopXMLNode & any other vars that would be obvious (A_LoopXMLNodeValue, A_LoopXMLNodeAttrib1_Name, A_LoopXMLNodeAttrib1_Value {or some way to access each attrib in turn})...(this is just an example, I know you can't create new "commands" in AutoHotkey, but achieving this goal is the point, however it's done)...I don't care if it's an actual "TreeWalker" or not...are you saying there is no current way to Loop over an XML & get each node/value/attribs in turn, in the order in the file?...of course I could just Loop over the file myself & regex to get the pieces I want, but then that don't use this function. To load the XML, you have to Loop over it, so can't you expose the read info in some way?...is XPath just the wrong tool for this?...if it is what do you recommend for me to achieve this?

With each new release can you state what you expect it to do?...I don't even know if XPath should support Looping over XML...it just looked like it could, but seems like it can't...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 14th, 2008, 8:14 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Quote:
Code:
xpath(test_db, "/car_db/cars[company='BMW' and product='850i']/id/text()")
/car_db/cars[company='BMW'][product='850i]

trueski wrote:
I need to read this file, Record.wme (Windows Media Encoder Settings) and replace the text
Wouldn't it be easier to use StringReplace? The XML way: xpath(x, "/WMEncoder/File[@LocalFileName='C:\Recording\ScreenRecord1.wmv']/@LocalFileName/text()", "C:\Recording\ScreenRecord2.wmv")

Quote:
I need to Loop, Parse, XML...& then get A_LoopXMLNode & any other vars
xpath itself doesn't provide a good way to do this other than the way I showed before.

Quote:
With each new release can you state what you expect it to do?
You mean version 4?

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 16th, 2008, 5:37 pm 
Titan wrote:
Quote:
Code:
xpath(test_db, "/car_db/cars[company='BMW' and product='850i']/id/text()")
/car_db/cars[company='BMW'][product='850i]


Hello Titan,
thanks for your tip. Unfortunately I didn't get it working :(

Here the example:

AHK-File
Code:
#Include xpath.ahk

; load XML-Database
xpath_load(car_db,      "DB\car_db.xml")

msgbox % xpath(car_db, "/car_db/cars[company='BMW'][product='850i']/id/text()")


XML-Database
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<car_db>
   <cars>
      <id>1</id>
      <company>BMW</company>
      <product>850i</product>
   </cars>
   <cars>
      <id>2</id>
      <company>BMW</company>
      <product>320</product>
   </cars>
   <cars>
      <id>3</id>
      <company>Mercedes</company>
      <product>A200</product>
   </cars>
   <cars>
      <id>4</id>
      <company>Testeintrag</company>
      <product>850i</product>
   </cars>
</car_db>



While
Code:
msgbox % xpath(car_db, "/car_db/cars[company='BMW']/id/text()")

and
Code:
msgbox % xpath(car_db, "/car_db/cars[product='850i']/id/text()")

works perfect, I cannot get
Code:
msgbox % xpath(car_db, "/car_db/cars[company='BMW'][product='850i']/id/text()")

to work.

Thanks for your help!
Martin


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2008, 11:53 am 
Offline

Joined: March 23rd, 2005, 7:53 am
Posts: 321
Location: Germany
Hi,

I'm still struggling with parsing an XML file.
This is part of the file:
Code:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE site PUBLIC "-//DUMMY//DTD iSpider News 4.0//EN" "http://www.dummy.de/DTD/spider/news_4_0.dtd">
<site>
  <baseref>http://newsrss.bbc.co.uk/</baseref>
  <enableUserAgent>false</enableUserAgent>
  <meta>
    <property name="rubric" value="topnews"/>
    <property name="lang" value="ENGLISH"/>
  </meta>
  <notes>Zuletzt getestet am 19.06.2008 (hhe)

von RSS auf normale Seiten umgestellt, das es Probleme beim FDGB gab

Fetches RSS streams from the BBC World Edition (there is also a UK edition).

2.1 -09.01.2007 (oko)
 clipping removes some unused CSS stylesheets.
2.0 -17.10.2005 (oko)
 now using smart clipping on original articles</notes>
  <children>
    <schedule>
      <enabled>true</enabled>
I want to get the value in red.
This is my ahk code:
Code:
xml := xpath_load ("\\spider.newbase.dmz\spider\server\resources\News\Production\bbc.co.uk - BBC News.news") ; load an XML document
aktiv := xpath (xml, "site/children/schedule/enabled/count()") ;
MsgBox, %aktiv%
As result I always get the name of the parsed file (\\spider.newbase.dmz\spider\server\resources\News\Production\bbc.co.uk - BBC News.news).
What am I doing wrong?

_________________
Hasso

Programmers don't die, they GOSUB without RETURN


Last edited by Hasso on August 26th, 2008, 2:05 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2008, 12:26 pm 
What if you try this?

Code:
xml := xpath_load ("\\spider.newbase.dmz\spider\server\resources\News\Production\bbc.co.uk - BBC News.news") ; load an XML document
aktiv := xpath (xml, "site/children/schedule/enabled/text()") ;
MsgBox, %aktiv%

not-tested

HTH
________________________________________________________
New here? Please, before you post...
1. Read the tutorial and try the examples. -> 2. Take a look at the command list to get an idea of what you could do. -> 3. Create your script. Consult the documentation and the FAQ if you get stuck. -> 4. Search the forum if you need help or examples, method 1 (forum), method 2 (site), method 3 (Google). -> 5. Post your code on the forum in the "Ask for Help" section if you still run into problems (but read this first). -> 6. There is more AHK on autohotkey.net and the Wiki and there is an AHK IRC chat.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2008, 1:01 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Hasso wrote:
As result I always get the name of the parsed file (\\spider.newbase.dmz\spider\server\resources\News\Production\bbc.co.uk - BBC News.news).
What am I doing wrong?
Hi Hasso, this should work:

Code:
xpath_load(xml, "\\spider.newbase.dmz\spider\server\resources\News\Production\bbc.co.uk - BBC News.news")
aktiv := xpath(xml, "/site/children/schedule/enabled/count()")
MsgBox, %aktiv%


Quote:
thanks for your tip. Unfortunately I didn't get it working
Looks like a bug. The entire method for evaluating predicates in xpath3 was written badly, hence modularization (xpath4_predicate) in the new version. Hopefully it will be fixed in the next commit.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2008, 1:25 pm 
Offline

Joined: March 23rd, 2005, 7:53 am
Posts: 321
Location: Germany
Thank you Titan, that did it!

_________________
Hasso

Programmers don't die, they GOSUB without RETURN


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 ... 18, 19, 20, 21, 22, 23, 24 ... 28  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Klark92 and 21 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