GoogleIt Mail IT Print IT PermaLinkLotusScript Utility Routines For XML DOM Processing
11:44:30 AM
Written By : Richard SchwartzCategory : IBM Lotus Notes And Domino
Location : Nashua, NH

A few weeks ago, I posted JavaScript ports of a few LotusScript routines that I initially wrote for my bloggregator and have found to be generally useful as a higher-level shell around processing XML using the standard DOM parsing routines. Since those JavaScript versions haven't been ripped apart by critics, I figure I can get away with posting the original LotusScript versions of those routines, and more. I had hoped the "and more" might include some brand new routines that I thought I could come up with to deal with some problems that Rocky mentioned, but alas my efforts to create some shell routines to encapsulate logic for updating the DOM tree ran into a bunch of brick walls. Still, there is more here than what I had ported to JavaScript. Quite a lot more. To accomodate limits within the Blogsphere template, I've had to separate the code for these functions into four separate pages.

The first page has the code for my routines for finding the first or Nth element with a given name starting at a point in an XML stream, and for processing XML text elements. These are the routines that formed the basis of the JavaScript routines posted earlier. The routines setTextItemFromElement() and setRichTextItemFromElement() are particularly useful, doing pretty much what their name implies: transferring text data out of an XML DOM element (i.e., the text found between an opening <tag> and it's closing </tag>) into a back-end text or rich text item. Both use the getElementText() function to actually take care of the dirty work of navigating down through the DOM tree and to deal with various error case as well as the possibility that text is enclosed within a CDATA section.

The second page has routines you can use to deal with text stored as an attribute of a tag (i.e., <tag value='this is the text we want'> rather than being enclosed between the <tag> and </tag>). The routines are called getElementAttributeText() setTextItemFromElementAttribute() and setRichTextItemFromElementAttribute(). There isn't as much under the covers here, but these routines do at least relieve you of having to remember to handle gracefully cases with nodes that don't actually have the attribute you are looking at.

The third and fourth pages both deal with processing dates. These were without question the most troublesome pieces of code in all of the RSS processing work that I have done. (For some good info on date formats in RSS feeds, see here.) I can't claim that they'll deal with every possible variation of date formatting that you might run into in an RSS, Atom or other XML stream, but the routines have been very stable for a long time, by which I mean that they haven't thrown errors or grossly misinterpreted a lot of dates that otherwise should have been processed, so I think you may find them useful. For processing what I refer to in the code as "natural language dates", they are set up for English only, but the initMonths() function (which you have to call before trying to process a date with these routines) is easy enough to modify for other languages. The setDateItemFromElement does what it's name implies: it extracts a date value from an XML element (i.e., the string between an opening and closing tag), and stores it in a back-end text item in a NotesDocument. This routine uses the LotusScript 'Like' statement to do pattern matching. It distinguishes between the following formats: ISO-8061 ("2005-06-02" and "2005-06-02T12:47:32-0500"), RFC-822 dates ("Thursday, 02 June 2005 01:23:45 EST" and "02 June 2005 01:23:45 EST"), and even plain old "06/02/2005 12:47" (but note that I don't even try to distinguish between mm/dd/yyyy and dd/mm/yyyy in this format, because I figure that anyone who is serious about getting dates right in XML really ought to be using the ISO or RFC compliant formats). If you want to use the routines at a lower level than setDateItemFromElement, you're welcome to, of course. They all return NotesDateTime, and they are convertISO8061Date(), convertISO8061DateTime(), and for the RFC-822 dates they are convertNaturalLangDate1() and convertNaturalLangDate2(). Sorry about the not so descriptive names of the latter functions, but I'm sometimes a bit superstitious about things. There was one routine convertNaturalLangDate(), which got too messy so I split it into two routines and when I was satisfied they were working I just left the names alone rather than risk annoying the coding demons.

This page has been accessed 2106 times. .
Comments :v

1. Bruce Elgort06/03/2005 08:12:14 PM


These routines are great! I have used them in my OS X Tiger Dahsboard Widgets.

Thanks for sharing this code with us.


2. tom06/21/2007 03:51:38 PM


3. vesoftware11/05/2013 10:24:32 PM

Agen Bola Promo 100% SBOBET IBCBET Casino Poker Tangkas Online
ITUPOKER.COM AGEN POKER ONLINE INDONESIA TERPERCAYA : Toko belanja online murah, Promo heboh jual barang hanya Rp 1,-

4. 51316914103/03/2016 08:57:22 PM

5. chenyingying10/17/2016 12:15:17 AM

6. dongdong806/28/2017 11:38:03 PM Ban.html Air Max.html

7. yaoxuemei11/29/2017 12:58:18 AM

8. chenlixiang12/08/2017 06:45:30 AM

Enter Comments^

Email addresses provided are not made available on this site.

You can use UUB Code in your posts.

[b]bold[/b]  [i]italic[/i]  [u]underline[/u]  [s]strikethrough[/s]

URL's will be automatically converted to Links

:-x :cry: :laugh: :-( :cool: :huh: :-) :angry: :-D ;-) :-p :grin: :rolleyes: :-\ :emb: :lips: :-o
bold italic underline Strikethrough

Remember me    

Monthly Archive
Responses Elsewhere

About The Schwartz


All opinions expressed here are my own, and do not represent positions of my employer.