| View previous topic :: View next topic |
| Author |
Message |
Titan
Joined: 11 Aug 2004 Posts: 5382 Location: /b/
|
Posted: Fri Apr 07, 2006 8:36 pm Post subject: XML Writer |
|
|
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 |
|
 |
Rabiator
Joined: 17 Apr 2005 Posts: 271 Location: Sauerland
|
Posted: Sat Apr 08, 2006 9:27 am Post subject: |
|
|
Excellent script, same as the ahk-style documentation!
Very useful, thanks, Titan!  |
|
| Back to top |
|
 |
netics
Joined: 21 Jan 2006 Posts: 21 Location: Korea
|
Posted: Sat Apr 08, 2006 1:08 pm Post subject: |
|
|
how can this be archived!?
great!! titan! |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5382 Location: /b/
|
Posted: Sat Apr 08, 2006 4:21 pm Post subject: |
|
|
| 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
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 |
|
 |
garry
Joined: 19 Apr 2005 Posts: 1182 Location: switzerland
|
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5382 Location: /b/
|
Posted: Sun Apr 09, 2006 10:05 am Post subject: |
|
|
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 |
|
 |
garry
Joined: 19 Apr 2005 Posts: 1182 Location: switzerland
|
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5382 Location: /b/
|
Posted: Sun Apr 09, 2006 10:21 am Post subject: |
|
|
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 |
|
 |
garry
Joined: 19 Apr 2005 Posts: 1182 Location: switzerland
|
|
| Back to top |
|
 |
Ace_NoOne
Joined: 10 Oct 2005 Posts: 333 Location: Germany
|
Posted: Tue Apr 11, 2006 1:29 pm Post subject: |
|
|
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 ), 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 ). 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 |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5382 Location: /b/
|
Posted: Tue Apr 11, 2006 4:17 pm Post subject: |
|
|
Thanks Ace_NoOne
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)  _________________
 |
|
| Back to top |
|
 |
Ace_NoOne
Joined: 10 Oct 2005 Posts: 333 Location: Germany
|
Posted: Wed Apr 12, 2006 9:23 am Post subject: |
|
|
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.
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.
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 |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5382 Location: /b/
|
Posted: Wed Apr 12, 2006 9:54 am Post subject: |
|
|
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 |
|
 |
Ace_NoOne
Joined: 10 Oct 2005 Posts: 333 Location: Germany
|
Posted: Wed Apr 12, 2006 10:11 am Post subject: |
|
|
Thanks for the quick response!
So the way I tried to to it was correct? That's encouraging!  |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5382 Location: /b/
|
Posted: Wed Apr 12, 2006 1:29 pm Post subject: |
|
|
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 |
|
 |
|