Skip to main content
This forum is closed to new posts and responses. New discussions are now taking place in the IBM Developer Answers forum.
Information Mgmt
New to Lotus
How to buy
Live demos
Technical library
Forums & community
Java™ technology
Open source
SOA and Web services
Web development
My developerWorks
About dW
Submit content

developerWorks  >  Lotus  >  Forums & community  >  Notes/Domino 6 and 7 Forum

Notes/Domino 6 and 7 Forum



PreviousPrevious NextNext

This is what you want
Willy Lorenzo 3.Jun.06 09:15 PM Lotus Notes
Applications Development 6.5.1 Windows 2000

The W3C is evil and XML is their evil spawn. There, I said it (someone had to!)

That said, here's how you work with XML in Notes.

1. Set up your XML as an input stream
2. Create a NotesDOMParser and give it the input stream
3. Parse
4. Navigate the DOM nodes.

Yes, I know...I lost you at step 1. Bear with me.

Below are three sets of information.

The first is the example XML that will be turned into the DOM
The second is the Schema for the XML you are parsing.
The third is the LotusScript that will create a DOM and extract data from it.

The first and second sets of information are references to use as you examine the DOM. Print them out and have them handy.

Make sure your computer is connected to the Internet. Copy and paste the LotusScript into a button. Turn on the debugger and click the button. Click Continue in the debugger.

At this point you should be at the Stop after clean up. Use the debugger to examine XMLDoc. Open "DocumentElement", then keep opening "FirstChild". Upon examining this XMLDoc you may determine that this is ridiculous. You are correct. XML certainly hasn't made my life any easier, and I doubt it's made anyone else's life easier. But I digress. You probaby want to read this thing, don't you...

You read a DOM by navigating through an excessively complex tree structure. Each branch is called a node. There are lots of different types of nodes. Bring up the Designer Help and look under:
Contents --> LotusScript/COM/OLE Classes --> LotusScript Classes A-Z --> NotesDOM*
Now you know what these things are. These are all the different types of nodes that you can encounter while navigating a DOM. They all have the same basic set of properties and methods, which they inherit from the NotesDOMNode class. Then each one add its own little twist to create its unique node-ness, and confuse the hell out of us normal people.

To get an idea of how to work with a DOM, think about having to work with a Notes document with the Items property and the GetFirstItem method. First you get the names with Items. You loop through the names to find the name you want. Then you use the name to actually get the notesitem you want, using the GetFirstItem. That's kinda what you have to do here.

This is where the Schema is required. XML describes data. the Schema describes the description. For example, the XML describes the Latitude as 37.41... the Schema says there something call Latitude. The Schema is important because there may be optional data elements defined. These may or may not be present in your XML, so you need to handle their absence.

The rest of the code shows how to put these fields into variables you can work with. You basically grab a node, then either grab the next child node or sibling node, depending on the data structure you're working with. The Schema will tell you what that structure is.

Each XML document has a root element. In our example, ResultSet is the root element. The code will grab that node first, then get its child, which should be a Result node. We then loop through the children of the result node. Those nodes should be the data nodes we are looking for. We grab the values and stick them in variables.

I did all this using Notes objects so you can see them in the debugger. However, I prefer to use the Microsoft XML object to do this stuff. It's more difficult to debug because you can't see the object properties in the debugger. You have to know the structure and understand what's going on. but I think it gives better control over the XML document. The property names and even the structure appears to be different between the Notes XML document and the Microsoft document. My thinking is, learn it once with Microsoft and just use that for everything.

This is the XML you are parsing

  <?xml version="1.0" ?>
- <ResultSet xmlns:xsi="" xmlns="urn:yahoo:maps" xsi:schemaLocation="urn:yahoo:maps">
- <Result precision="address" warning="The exact location could not be found, here is the closest match: 701 First Ave, Sunnyvale, CA 94089">
  <Address>701 FIRST AVE</Address>
- <!-- compressed/chunked Sat Jun  3 18:12:45 PDT 2006

This is the Schema for the above XML

  <?xml version="1.0" encoding="utf-8" ?>
- <xs:schema xmlns:xs="" targetNamespace="urn:yahoo:maps" xmlns="urn:yahoo:maps" elementFormDefault="qualified">
- <xs:element name="ResultSet">
- <xs:complexType>
- <xs:sequence>
  <xs:element name="Result" type="ResultType" minOccurs="0" maxOccurs="50" />
- <xs:complexType name="ResultType">
- <xs:sequence>
  <xs:element name="Latitude" type="xs:decimal" />
  <xs:element name="Longitude" type="xs:decimal" />
  <xs:element name="Address" type="xs:string" />
  <xs:element name="City" type="xs:string" />
  <xs:element name="State" type="xs:string" />
  <xs:element name="Zip" type="xs:string" />
  <xs:element name="Country" type="xs:string" />
  <xs:attribute name="precision" type="xs:string" />
  <xs:attribute name="warning" type="xs:string" use="optional" />
- <!-- compressed/chunked Sat Jun  3 18:18:23 PDT 2006

Here's the LotusScript that reads it. It's easier to read the comments after it's been pasted into a button. Don't copy the "Sub..." and "End Sub"

Sub Click(Source As Button)
Dim ss As New NotesSession
Dim db As NotesDatabase
Dim domParser As NotesDOMParser
Dim tempdoc As NotesDocument
Dim attachment As NotesEmbeddedObject
Dim XMLDoc As Variant
Dim geoinput As NotesStream
Dim AddressIndex As Integer
Dim geopath As String
' Nodes to handle data
Dim RootElement As Variant
Dim Result As Variant
Dim attrib As Variant
Dim node As Variant
' Strings to receive data
Dim str_geoprecision As String
Dim str_geowarning As String
Dim str_latitude As Single
Dim str_longitude As Single
Dim str_geoaddress As String
Dim str_geocity As String
Dim str_geostate As String
Dim str_geozip As String
Dim str_geocountry As String

' The next 7 lines of code (not comments) comprise one way to get XML to the XML parser.
' There are others so don't think you have to start out this way.
' Get the current db. You'll need to create a doc to get the sample XML
Set db = ss.CurrentDatabase
' It's incredible that we need the next 5 lines but there's no simple way to get XML from a URL in Notes.
' In real apps I use the Windows XML object which does everything these first 12 lines does with a single line of code.
' Create a document containing some XML. Doesn't really matter what it is. I was playing with yahoo geocoding so...
Set tempdoc = db.GetDocumentByURL("")
' Get the attachment that the GetDocumentByURL process creates and write it to the temp directory.
Set attachment = tempdoc.GetAttachment("geocode")
geopath = Environ("Temp") & "\geo.xml"
Call attachment.ExtractFile(geopath)
' Create a NotesStream and use it to open the XML.
Set geoinput = ss.CreateStream
Call geoinput.Open(geopath)
' Okay, here's the XML parser object. It takes several different parameter types as input streams but most are useless.
' There are two that are of use to us. The first is NotesRichTextItem. If you put your XML in a richtext item and then
' give that RTI to the parser, it will parse the XML and create the DOM. The second is NotesStream.
' Basically, NotesStream is an object that represents a file. It's a complex way to pass a text file to the parser.
' Put your XML in a text file, "Open" it with a NotesStream, then give the NotesStream to the Parser.
' This is the method used in this example.
Set domParser = ss.CreateDOMParser( geoinput )
' Now PARSE!
Call domParser.Parse
' The NoteDOMParser contains the DOM, so lets get it.
Set XMLDoc = domParser.Document
' And there you have it. XMLDoc is your DOM (Document Object Model)

' Clean up
Call tempdoc.Remove(True) ' for some reason this doc gets saved so lets kill it.
Call geoinput.Close
Kill geopath

' Use the debugger to review XMLDoc. You will quickly realize that an XML document is a complex object.
' Every XML document has one Root Element. Lets grab that now.
Set RootElement = XMLDoc.documentElement
' Our root element should be ResultSet. Lets see if it is.
Msgbox("Root Element name: " & rootElement.nodeName)
' Assuming that's what we got, lets get its first child
Set Result = rootElement.firstchild
' Did we really get a "Result"?
Msgbox( "Child Node Name: " & Result.nodeName )
' Assuming that's what we got...
' First get the Attributes
Set attrib = Result.getAttributeNode("precision")
str_geoprecision = attrib.AttributeValue
Set attrib = Result.getAttributeNode("warning")
If attrib Is Nothing Then ' The "warning" attribute is optional so make sure it exist before trying to use it.
str_geowarning = "No Warning"
str_geowarning = attrib.AttributeValue
End If
' Next, get the nodes of the Result node. We're going to grab each node
' and update the appropriate variable based on the nodeName.
Set node = result.Firstchild
For addressindex = 1 To Result.NumberOfChildNodes
Select Case node.nodeName
Case "Latitude"
str_latitude = Csng(node.firstchild.nodevalue)
Case "Longitude"
str_longitude = Csng(node.firstchild.nodevalue)
Case "Address"
str_geoaddress = node.firstchild.nodevalue
Case "City"
str_geocity = node.firstchild.nodevalue
Case "State"
str_geostate = node.firstchild.nodevalue
Case "Zip"
str_geozip = node.firstchild.nodevalue
Case "Country"
str_geocountry = node.firstchild.nodevalue
End Select
Set node = node.NextSibling


End Sub

Here's another way to get a DOM

Sub Click(Source As Button)
Dim ss As New NotesSession
Dim db As NotesDatabase
Dim domParser As NotesDOMParser
Dim tempdoc As NotesDocument
Dim tempRTI As NotesRichTextItem
Dim TempXMLDoc As Variant
Dim XMLDoc As Variant

Set db = ss.CurrentDatabase
Set tempdoc = db.CreateDocument
Set tempRTI = tempdoc.CreateRichTextItem("Body")

' The next 6 lines are simply to get an XML document into a rich text field.
' You can replace these lines with whatever LotusScript is necessary
' to load your XML into the rich text field.
' This particular process actually creates a Microsoft DOM and gets the XML from it.
Set TempXMLDoc = CreateObject("Msxml2.DOMDocument.4.0")
TempXMLDoc.async = False
TempXMLDoc.validateOnParse = False
TempXMLDoc.resolveExternals = False
Call TempXMLDoc.Load("")
' At this point I would be done. TempXMLDoc is a Microsoft DOM and I can get the data I need from it.
' Method and property names are different from the Notes DOM, however, as well as the structure of the DOM.

' Move the XML text to the rich text field.
Call tempRTI.AppendText( TempXMLDoc.xml )
' give the RTI to the parser as an input parameter
Set domParser = ss.CreateDOMParser( TempRTI )
Call domParser.Parse
'Get the document
Set XMLDoc = domParser.Document


End Sub

Using Domino XML libraries to handl... (Cameron Donnell... 1.Jun.06)
. . RE: Using Domino XML libraries to h... (Ian Tree 2.Jun.06)
. . This is what you want (Willy Lorenzo 3.Jun.06)

Document Options

  Document options
Print this pagePrint this page

Search this forum

Forum views and search

  Forum views and search
Date (threaded)
Date (flat)
With excerpt
Advanced search

Member Tools

RSS Feeds

 RSS feedsRSS
All forum posts RSS
All main topics RSS
More Lotus RSS feeds


Forum use and etiquette
Native Notes Access
Web site Feedback

Lotus Support

 Lotus Support
IBM Support Portal - Lotus software
Lotus Support documents
Lotus support by product
Lotus support downloads
Lotus support RSS feeds


IBM Composite Applications
IBM Mashup Center
IBM Connections
IBM Connections Cloud Developers
IBM Docs
IBM Forms
IBM Mobile Connect
IBM Sametime
IBM SmartCloud for Social Business
IBM Web Experience Factory
Lotus Domino
Lotus Domino Designer
Lotus Expeditor
Lotus Foundations
Lotus iNotes
Lotus Instructor Community Courseware
Lotus Notes
Lotus Notes & Domino Application Development
Lotus Notes Traveler
Lotus Protector
Lotus Quickr
Lotus Symphony
IBM Web Content Manager
WebSphere Portal

Lotus Forums

 Lotus Forums
Notes/Domino 9.0
Notes/Domino 8.5 + Traveler
Notes/Domino XPages development forum
Notes/Domino 8
Notes/Domino 6 and 7
IBM Connections
IBM Mobile Connect
IBM Sametime
IBM SmartCloud Notes
Lotus Enterprise Integration
Lotus Protector
Lotus Quickr
Lotus SmartSuite