|
|
|
|
|
|
|
|
|
|
Parsing XML with LotusScript and Microsoft's XML object (continued)
Installing and loading MSXML Sadly, I haven't found a way of just installing the MSXML component by itself. MSXML only gets installed when you install Internet Explorer 5 or there is an earlier version in Internet Explorer 4. It also doesn't come with any documentation but there are books available (see the Product Availability and Resources section at the end of this article). There's also a comprehensive online tutorial on the Microsoft site. Once installed (you'll probably need to fully install IE5), try running the following agent:
Dim xml As Variant
Set xml = CreateObject("Microsoft.XMLDOM")
Msgbox xml.async
|
You should get the message 'True' when you run this. If you get an error, try re-installing Internet Explorer.
You can find this agent included as SimpleTest in the sample database. Download instructions are in Product Availability and Resources at the end of this article.
The initial XMLHeadlines agent I created a simple database with a single document called News. This had two rich-text fields, one for the XML original and one for my HTML output. My first agent, XMLHeadlines, would download an XML file, place the contents in the XML field, and parse the data. I would then walk the tree to get the information I wanted and wrap that in HTML. Luckily MSXML allows you to load a file from a local source, so I didn't have to spend loads of time online while I was debugging it.
There are a number of key pieces of the agent. Table A contains a list of code segments and descriptions.
| Code segment |
Description |
| Set xml = CreateObject("Microsoft.XMLDOM"). |
Creates an instance of the object in a variant. |
| xml.async=False |
Default is asynchronous loading. We need synchronous so it waits for the file. To speed up loading set validateOnParse=false as well so it simply checks for "well-formedness". |
| xml.load(URL or file name) |
Loads a file or a URL. Returns true or false. |
| originalfile$=xml.xml |
Returns the original XML as a string |
| title=xml.selectSingleNode("rdf:RDF/channel/title").text |
Get the value of a single node as a text string; returns DominoPower News Center in listing above. |
| set root=xml.selectNodes("rdf:RDF/item") |
Return a node list matching the given pattern (i.e. all the item nodes). Use Forall to run through the list. |
| link$=x.childNodes(1).text |
For each node in the node list, get the first child nodes' value; returns the link item in listing above. You can use x.childNodes(1).nodeName to get the name. |
This worked pretty well and gave me the data I wanted. However, I also wanted to try and use style sheets as an alternative. The advantage of style sheets is that you can have one XML file and get different outputs depending on which style sheet you use. This is a bit like using different sub-forms in a form.
[ Prev | Next ]
|
|
|
|
|
|
-- Advertisement --
2-Minute Tutorials
How do I...
- integrate MS Office or OpenOffice with Notes?
- create cross-tab reports and charts?
- print serial letters and mailing labels?
- create PDFs in Lotus Notes?
Check out the 2-minute tutorials here. |
-- Advertisement --
SECURTRAC - MONITOR AND CONTROL YOUR DOMINO ENVIRONMENT
When it comes to your business, how do you ensure compliance with SOX, HIPAA or other industry driven regulations? Use SecurTrac to monitor and audit the life cycle of all objects in your Domino environment.
- Database Monitor
- Mail Monitor
- Domino Directory Monitor
- Notes.ini File Monitor
- Intrusion Detection Monitor
Click here for details and a free evaluation copy. |
|
|
|
|
|
|