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 

XML Writer
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Titan



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

PostPosted: Fri Apr 07, 2006 8:36 pm    Post subject: XML Writer Reply with quote

This function writes data to all types of XML files (e.g. RSS, Atom, and even custom ones). It can write attribute values, change processor settings and process fused tags. It's only around 4kb and works as fast as IniWrite.

For a complete guide on this function including an example, see the XMLWrite-Doc (right-click and choose 'Save As').

This screenshot (from the example) shows something written with this function and viewed in Internet Explorer:


Latest version: 1.08 - Tuesday 30th May 2006

Download (4kb)
_________________



Last edited by Titan on Wed May 31, 2006 9:42 am; edited 5 times in total
Back to top
View user's profile Send private message Visit poster's website
Rabiator



Joined: 17 Apr 2005
Posts: 271
Location: Sauerland

PostPosted: Sat Apr 08, 2006 9:27 am    Post subject: Reply with quote

Excellent script, same as the ahk-style documentation!
Very useful, thanks, Titan! Cool
Back to top
View user's profile Send private message
netics



Joined: 21 Jan 2006
Posts: 21
Location: Korea

PostPosted: Sat Apr 08, 2006 1:08 pm    Post subject: Reply with quote

how can this be archived!?

great!! titan!
Back to top
View user's profile Send private message
Titan



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

PostPosted: Sat Apr 08, 2006 4:21 pm    Post subject: Reply with quote

netics wrote:
how can this be archived!?
A lot of research on XML and a long time on testing and debugging. It was fun and I enjoyed the challenge. Thanks for the appreciation Rabiator and netics Very Happy

By the way, if anybody has any suggestions please let me know. I intentionally created the flexible options parameter for expansions and such. Edit: I also updated the XMLWrite-Doc with more info.
_________________



Last edited by Titan on Sun Apr 09, 2006 10:41 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
garry



Joined: 19 Apr 2005
Posts: 1182
Location: switzerland

PostPosted: Sun Apr 09, 2006 9:37 am    Post subject: Reply with quote

hello Titan,
how use the script, try to read :
http://www.abc.net.au/rn/podcast/feeds/breakfast.xml
http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/uk/rss.xml
Back to top
View user's profile Send private message
Titan



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

PostPosted: Sun Apr 09, 2006 10:05 am    Post subject: Reply with quote

Thanks garry, I looked at those links but they were just other XML files? There is an XML Reader function if thats what you wanted.
_________________

Back to top
View user's profile Send private message Visit poster's website
garry



Joined: 19 Apr 2005
Posts: 1182
Location: switzerland

PostPosted: Sun Apr 09, 2006 10:16 am    Post subject: Reply with quote

sorry Titan,
I'm not good in mathe and english
XML reader, how use to read http://www.abc.net.au/rn/podcast/feeds/breakfast.xml
XMLRead(file, tree, type=0) { ; XMLRead() by Titan - revision 20060226
....
Back to top
View user's profile Send private message
Titan



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

PostPosted: Sun Apr 09, 2006 10:21 am    Post subject: Reply with quote

XMLRead() and XMLWrite() are quite different so the parameters aren't the same. If you find any bugs with XML Reader please report it in its thread.
_________________

Back to top
View user's profile Send private message Visit poster's website
garry



Joined: 19 Apr 2005
Posts: 1182
Location: switzerland

PostPosted: Sun Apr 09, 2006 10:36 am    Post subject: Reply with quote

no bugs, I'm just bad in mathe and programming, I' ll try to read your help doc
once wrote (a bad written) script with listview, put in xy.xml and doubleclick to read
http://autohotkey.net/file/users/Members/garry/BBC1.jpg
http://autohotkey.net/file/users/Members/garry/BBC2.jpg
Back to top
View user's profile Send private message
Ace_NoOne



Joined: 10 Oct 2005
Posts: 333
Location: Germany

PostPosted: Tue Apr 11, 2006 1:29 pm    Post subject: Reply with quote

Titan, you're great! (redundancy not intended)
This is a major contribution that will, in combination with your XmlRead function, greatly enhance the potential of AHK!
Once we're sure that this function works as well as XmlRead does, it should be seriously considered to include both functions in the AHK core.

Anyways, I'm still struggling to get it working the way I want it to though - it's more complex than you'd think...
However, that's probably my fault (the British air seems to inhibit my mental functions Razz ), as your documentation is really well-done (great job adopting the AHK doc's style).

One problem is that I can't seem to get the indentation working. I thought I had it for a second, but then I couldn't reproduce it for some reason (see above Surprised ). Could you please post an short example of how it's supposed to be done?
Also, there was at least one instance where the tag name was miraculously followed by a space ("<item >"), but I haven't been able to reproduce that either. (As you might have noticed, my mind is kinda messy at the moment - my apologies for that.)

Anyways, truly an impressive job!
Back to top
View user's profile Send private message
Titan



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

PostPosted: Tue Apr 11, 2006 4:17 pm    Post subject: Reply with quote

Thanks Ace_NoOne Smile

I tested the indentation and it seems to work. Here is an example:
Code:
file = %temp%\dl.xml
URLDownloadToFile, http://export.cnet.com/export/download/rss-hot-download.com.com.xml, %file%
XMLWrite(file, "rss.channel.example[-1]", "indented-text", "", "IndS")
RunWait, notepad "%file%"
FileDelete, %file%
I'll have a deeper look into this if you still find problems.

During parsing, an extra space is needed (to prevent confusion with "example" and "examples") but it should be taken out before the changed XML file is saved. I have not noticed this - can you confirm this is a bug? In the meantime, such is not technically an error, your XML document will be valid nevertheless.

Check out the example in the XMLWriter-Doc because it's an effective way to understand how to make the function calls (and one of the very few scripts I comment on) Razz
_________________

Back to top
View user's profile Send private message Visit poster's website
Ace_NoOne



Joined: 10 Oct 2005
Posts: 333
Location: Germany

PostPosted: Wed Apr 12, 2006 9:23 am    Post subject: Reply with quote

I know that an extra space doesn't make the XML invalid, but I'm kinda nit-picky when it comes to that (plus XML is verbose enough already).
Still, it's just a minor issue and I haven't been able to reproduce it yet (might have been caused by something like improper use of parameters in the early learning phase), so don't worry about it unless I discover that it actually is a bug.

As I said, your documentation of this function is very good - it's just the treacherous complexity of XML that makes this kinda difficult, for me at least. Embarassed
I've tried looking at your code to figure out a few things myself, but due to the lack of comments it was quite hard to follow. Yet, as they say, "Real Programmers don't need comments--the code is obvious", so I'll have to live with that. Smile

Anyways, it seems that I'm trying to use the indentation - and maybe even the whole function - other than intended. For example, let's say I got an XML file like this:
Code:
<root>
   <category>
      <item>this is the default item</item>
   </category>
</root>

Now I use XMLWrite(file, "root.category.item[-1]", "this is a new item", "", "IndT") to add a new item before the default one - but what I get is quite a mess (structure/hierarchy- and indentation-wise):
Code:
<root>
   <category>
      <item>this is the default item</item>
   </category>
<root><category>
         <item>this is a new item</item></category></root></root>

Here's what I think it should look like:
Code:
<root>
   <category>
      <item>this is a new item</item>
   </category>
   <category>
      <item>this is the default item</item>
   </category>
</root>

I reckon this is my fault, and I'm probably being very stupid here, but I can't figure out what I'm doing wrong...
Back to top
View user's profile Send private message
Titan



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

PostPosted: Wed Apr 12, 2006 9:54 am    Post subject: Reply with quote

Ah, there seems to be a problem with how the parser calculates the index of an element. After some testing with your script the parser assumed the following indexes:

root: +1; category: +1; item: +1; root: +1; category: +1; item: -1;
should be: root: +1; category: +1; item: +1; root: 0; category: 0; item: -1;

This is where the problem is in the code but there could be minor issues elsewhere that contributes to this problem.
Code:
      If !(InStr(s, "<" . e . " ", 1) or InStr(s, "<" . e . ">", 1)) and i > -1 ;Line 38
         i =+1 ; Line 39

I'll check it out in my free time and fix it. Sorry for the inconvenience.
_________________

Back to top
View user's profile Send private message Visit poster's website
Ace_NoOne



Joined: 10 Oct 2005
Posts: 333
Location: Germany

PostPosted: Wed Apr 12, 2006 10:11 am    Post subject: Reply with quote

Thanks for the quick response!

So the way I tried to to it was correct? That's encouraging! Smile
Back to top
View user's profile Send private message
Titan



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

PostPosted: Wed Apr 12, 2006 1:29 pm    Post subject: Reply with quote

In version 1.01 I fixed this minor index bug. It was actually caused by incorrect string trimming if a processor is not present (and not what I said above). The indentation is still not perfect but I'm working on it for the next release.
_________________

Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
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