AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

xpath v3 - read and write XML documents with XPath syntax
Goto page Previous  1, 2, 3, ... 26, 27, 28  Next
 
Post new topic   This topic is locked: you cannot edit posts or make replies.    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Titan



Joined: 11 Aug 2004
Posts: 5043
Location: /b/

PostPosted: Tue Apr 10, 2007 3:45 pm    Post subject: Re: Operators ">" and "=" Reply with quote

Venia Legendi wrote:
Why ist Book2 with a price of 2.0 found by [price>2.0] and it's not found by [price=2.0]?
The parser is case sensitive so "2" should not work and "2.0" should. Could you show the XML document you're using so I can test this?
_________________
Chat (IRC) • PlusNet • Scripts • IronAHK • Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Venia Legendi



Joined: 27 May 2005
Posts: 35

PostPosted: Tue Apr 10, 2007 4:20 pm    Post subject: Reply with quote

Hello, thank you for the prompt answer, the XML-file ist generated by the example I posted.
Code:

<?xml version="1.0" encoding="iso-8859-1"?>

<bookstore>
 <book>
  <title>title1
   </title>
  <price>1.0
   </price>
  </book>
 <book>
  <title>title2
   </title>
  <price>2.0
   </price>
  </book>
 <book>
  <title>title3
   </title>
  <price>3.0
   </price>
  </book>
 <book>
  <title>title4
   </title>
  <price>4.0
   </price>
  </book>
 <book>
  <title>title5
   </title>
  <price>5.0
   </price>
  </book>
 </bookstore>
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5043
Location: /b/

PostPosted: Tue Apr 10, 2007 7:01 pm    Post subject: Reply with quote

Sorry I missed that; I fixed this in version 1.02.
Both [price=2] and [price=2.0] will work now since AutoHotkey sees them as the same numbers in expressions.
_________________
Chat (IRC) • PlusNet • Scripts • IronAHK • Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Venia Legendi



Joined: 27 May 2005
Posts: 35

PostPosted: Tue Apr 10, 2007 7:16 pm    Post subject: Reply with quote

Thank you, perfect.
Back to top
View user's profile Send private message
eljose
Guest





PostPosted: Thu Apr 12, 2007 11:05 pm    Post subject: help me Reply with quote

This is my first post, so first of all hello everybody.
I'm learning XML now, and a have a problem. Here is my XML code

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE tv SYSTEM "xmltv.dtd">

<tv generator-info-name="EPG4cplus - mfsav mod">
  <channel id="00000001">
    <display-name>CANAL+</display-name>
  </channel>
   <programme start="20070414005000" stop="20070414005500" channel="00000001">
    <title>NBA+++++</title>
    <category>nosequepassa</category>
  </programme>
  <programme start="20070414005500" stop="20070414015500" channel="00000001">
    <title>Caribe salvaje</title>
    <category>documentales naturaleza</category>
  </programme>
</tv>


I need to filter the start and stop attributes with actual datetime to show what program is on tv at the moment. and i have no luck.
please help me.
thanks

ough! my source code is:
Code:

#Include XPath.ahk
a = C:\down\autohotkey\xpath\cplus.xml
book := XmlDoc(a)
latest := XPath(book, "/tv/programme[@stop>=A_Now]/title[1]/text()")
MsgBox, %latest%
XmlDoc("test2.xml", latest)
Back to top
Venia Legendi



Joined: 27 May 2005
Posts: 35

PostPosted: Thu Apr 12, 2007 11:15 pm    Post subject: Re: help me Reply with quote

eljose wrote:

Code:

latest := XPath(book, "/tv/programme[@stop>=A_Now]/title[1]/text()")

Code:

latest := XPath(book, "/tv/programme[@stop>=" A_Now "]/title[1]/text()")
; A_Now in String is A_Now as String

BTW: test2.xml ist not XML, it just the string you receive
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5043
Location: /b/

PostPosted: Thu Apr 12, 2007 11:16 pm    Post subject: Reply with quote

All function parameters are expressions so you have to seperate strings from variables like: "/tv/programme[@stop>=" . A_Now . "]/title[1]/text()"

Edit: Venia Legendi beat me to it, thanks Smile
_________________
Chat (IRC) • PlusNet • Scripts • IronAHK • Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
eljose



Joined: 13 Apr 2007
Posts: 1
Location: Spain

PostPosted: Fri Apr 13, 2007 5:54 pm    Post subject: thanks Reply with quote

thanks for that quick response (and excuse me for my bad written english) to Ttitan and Venia Legendi
I've tried and works, but reading from http://www.w3.org/TR/xpath-functions/#func-current-dateTime
i've found that function and tried to chace A_Now with current-dateTime. Oh!, surprise i am blocked again.
Can you help me.

thanks in advance.
_________________
Visca el Barηa
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5043
Location: /b/

PostPosted: Fri Apr 13, 2007 6:36 pm    Post subject: Reply with quote

Those functions aren't supported since you can do most of those kind of calculations yourself with AutoHotkey. At the moment only text() and remove() work.
_________________
Chat (IRC) • PlusNet • Scripts • IronAHK • Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Titan



Joined: 11 Aug 2004
Posts: 5043
Location: /b/

PostPosted: Mon Apr 16, 2007 12:15 am    Post subject: Reply with quote

New in v1.03:
  • Changed function to return nothing if a node is not found
  • Fixed root '//' expression to be able to parse child nodes
  • Fixed text() function to retrieve only the highest level node content
  • Corrected position where new attributes were inserted

Known limitation: '//' will apply to child nodes if used
_________________
Chat (IRC) • PlusNet • Scripts • IronAHK • Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
daonlyfreez



Joined: 16 Mar 2005
Posts: 841
Location: Berlin

PostPosted: Sat Jul 21, 2007 3:28 pm    Post subject: Reply with quote

I encountered a small problem with XPath.

This example code:

Code:
#Include %A_ScriptDir%\XPath.ahk

settingsFile := XmlDoc(A_ScriptDir . "\settings.xml")

guiTitle := XPath(settingsFile, "/settings/window/@title/text()")
guiPosX := XPath(settingsFile, "/settings/window/@x/text()")
guiPosY := XPath(settingsFile, "/settings/window/@y/text()")
guiPosW := XPath(settingsFile, "/settings/window/@w/text()")
guiPosH := XPath(settingsFile, "/settings/window/@h/text()")

Gui, +Lastfound +Resize
hWnd := WinExist()

Gui, Add, Text, , Just testing...`n`nResize me, reposition me, and close me`n`nIf you reopen me`, the last saved settings will be used`nfor positioning.
Gui, Show, x%guiPosX% y%guiPosY% w%guiPosW% h%guiPosH%, %guiTitle%
Return

GuiClose:
   WinGetPos, nowX, nowY, nowW, nowH, ahk_id %hWnd%

   nowW := nowW - 8
   nowH := nowH - 54
   
   XPath(settingsFile, "/settings/window/@x/text()", nowX)
   XPath(settingsFile, "/settings/window/@y/text()", nowY)
   XPath(settingsFile, "/settings/window/@w/text()", nowW)
   XPath(settingsFile, "/settings/window/@h/text()", nowH)
   XmlDoc(A_ScriptDir . "\settings.xml", settingsFile)

   ExitApp
Return


and this corresponding settings.xml file

Quote:
<?xml version="1.0" encoding="UTF-8"?>

<settings>
<window title="XPath Test" x="10" y="11" w="271" h="91">
</settings>


Every time after I wrote the values back to the file, the file has extra empty lines at the top.

Quote:
<?xml version="1.0" encoding="UTF-8"?>


<settings>
<window title="XPath Test" x="10" y="11" w="271" h="91">
</settings>


Quote:
<?xml version="1.0" encoding="UTF-8"?>




<settings>
<window title="XPath Test" x="10" y="11" w="271" h="91">
</settings>


... etcetera. Could this be fixed?
_________________
My AHK stuff on ahk.net / on DropBox (mirror) / @home (if online)
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5043
Location: /b/

PostPosted: Sat Jul 21, 2007 3:55 pm    Post subject: Reply with quote

Strange that doesn't happen for me.
_________________
Chat (IRC) • PlusNet • Scripts • IronAHK • Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
daonlyfreez



Joined: 16 Mar 2005
Posts: 841
Location: Berlin

PostPosted: Sat Jul 21, 2007 4:04 pm    Post subject: Reply with quote

A new line character does get added for me, between all main/parent nodes btw after a save, not only at the top of the document... weird
_________________
My AHK stuff on ahk.net / on DropBox (mirror) / @home (if online)
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5043
Location: /b/

PostPosted: Sat Jul 21, 2007 4:07 pm    Post subject: Reply with quote

Have you got the latest version 1.03? Try downloading xpath.ahk again, but rather than copying the text click 'Save As...' on the link so characters don't get somehow converted.
_________________
Chat (IRC) • PlusNet • Scripts • IronAHK • Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
daonlyfreez



Joined: 16 Mar 2005
Posts: 841
Location: Berlin

PostPosted: Sat Jul 21, 2007 4:32 pm    Post subject: Reply with quote

Did exactly as you suggested, still the issue remains...
_________________
My AHK stuff on ahk.net / on DropBox (mirror) / @home (if online)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   This topic is locked: you cannot edit posts or make replies.    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, ... 26, 27, 28  Next
Page 2 of 28

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group