Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Need to create Notes documents from XML text file

Posted on 2006-04-05
10
Medium Priority
?
1,092 Views
Last Modified: 2013-12-18
I've used delimited text files to create Notes documents many times, but before I write yet another text parsing script I'd like to see if I can use XML since the exported data file is in XML format this time.  Here is my situation, I have a text file exported from another application that I need to use to create and populate new documents in Notes.  The fields are all text values.  This application needs to run on the Notes for OS/X client, so using the Microsoft XML toolkit isn't an option.
Does anyone have a code sample to help get me started?
Thanks
0
Comment
Question by:Ed_CLP
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 3

Expert Comment

by:NARoberts
ID: 16381895
I know that notes 7 has alot more XML features built in.  What version are you on?
0
 

Author Comment

by:Ed_CLP
ID: 16382042
I'm using version 6.5.4.  This application needs to run on the user client (no version 7 available yet for Mac OS/X).
0
 
LVL 3

Expert Comment

by:NARoberts
ID: 16382117
Here is a developerworks article on XML in 6.  I've never done it yet so I don't know that I can be much help to you, sorry.

http://www-128.ibm.com/developerworks/lotus/library/ls-LS_XML1/index.html

Also, a redbook.
http://www.redbooks.ibm.com/abstracts/sg246207.html
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16382185
Try first to export some documents from a Notes database to XML. There are some easy scripts in the Help database, look for the NotesDXLExporter method.
0
 

Author Comment

by:Ed_CLP
ID: 16382241
My LotusScript parser is looking better already!  I also found an article on Lotus Advisor from May 2001 that uses SAX and a Java agent to do what I'm trying to accomplish.  I'll hold the question open a bit longer before I use my original method.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16382292
Of course, there is the parallel NotesDXLImporter to get documents in...
0
 

Author Comment

by:Ed_CLP
ID: 16382410
It looks like NotesDXLImporter would work - can you find an example of using this to create populated documents in a Notes DB?  I can only find an example to create a new DB, not populate documents.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16382530
Ah, okay. The other day, I wrote some script to export documents from one db to import them into a second. The file was to be sent to some other party through mail.

Option Public
Option Explicit

Sub ExportDocs(dc As NotesDocumentCollection, filename As String)
    Dim ns As New NotesSession
    Dim db As NotesDatabase
    Dim stream As NotesStream

    Set db= ns.CurrentDatabase

    REM Open xml file named after current database
    Set stream= ns.CreateStream
    If Not stream.Open(filename) Then
        Messagebox "Cannot open " & filename,, "Error"
        Exit Sub
    End If
    Call stream.Truncate

    REM Export note collection as DXL
    Dim exporter As NotesDXLExporter
    Set exporter= ns.CreateDXLExporter(dc, stream)
    Call exporter.Process
End Sub

Sub ImportDocs(filename As String)
    Dim ns As New NotesSession
    Dim db As NotesDatabase
    Dim stream As NotesStream

    Set db= ns.CurrentDatabase

    REM Open xml file named after current database
    Set stream= ns.CreateStream
    If Not stream.Open(filename) Then
        Messagebox "Cannot open " & filename,, "Error"
        Exit Sub
    End If
    If stream.Bytes = 0 Then
            Messagebox "File did not exist or was empty",, filename
            Exit Sub
    End If

    REM Export note collection as DXL
    Dim importer As NotesDXLImporter
    Set importer= ns.CreateDXLImporter(stream, db)
    Call importer.Process
End Sub

Watch it though, it will import ANYTHING, even design documents!
0
 
LVL 14

Expert Comment

by:p_partha
ID: 16383118
YOu can try this download:
http://www.chc-3.com/downloads.htm

Partha
0
 
LVL 15

Accepted Solution

by:
mshogren earned 1000 total points
ID: 16385448
Hi, I am coming in late on this one but hopefully I can provide some help.  If all you are doing is creating documents and fields on notes documents from an XML document and you don't want to write a text parsing loop then try using the NotesDOMParser or NotesSAXParser to do the parsing for you.  I have done this recently and have provided two code examples below.  Notes that the extra code you write for the SAX parser results in faster processing for simple XML documents, but if you have a complex DOM structure in your XML documents it might be easier to use the DOM parser.

NotesDOMParser example:

Sub Initialize
      Dim startTime As Single
      startTime = Timer
      
      Dim ses As New NotesSession
      Dim db As NotesDatabase
      Dim doc As NotesDocument
      Dim parser As NotesDOMParser
      Dim xml As NotesStream
      Dim root As NotesDOMDocumentNode
      
      Set db = ses.CurrentDatabase
      
      'Open the XML file
      Set xml = ses.CreateStream
      If Not xml.Open(XML_FILE) Then
            Exit Sub
      End If
      
      'parse the XML into a DOM tree
      Set parser = ses.CreateDOMParser(xml)
      parser.Process
      Set root = parser.Document
      
      'Get a list of EMPLOYER elements
      Dim employers As NotesDOMNodeList
      Set employers = root.GetElementsByTagName("EMPLOYER")
      
      Dim el As NotesDOMNode
      Dim i As Long
      For i = 1 To employers.NumberOfEntries
            Set doc = db.CreateDocument
            'read all the child elements of the EMPLOYER element
            Set el = employers.GetItem(i).FirstChild
            Do While Not el.NextSibling.IsNull
                  'We are only checking XML elements not attributes or text nodes
                  If el.NodeType = 1 Then
                        Dim fieldName As String
                        Dim fieldValue As String
                        
                        'transform the element name to the correct field name (probably a select statement)
                        fieldName = el.LocalName
                        'transform the element value to the correct field value
                        'Note: this value is only correct based on the assumption that
                        'the sub-elements of EMPLOYER contain no sub-elements themselves
                        fieldValue = el.FirstChild.NodeValue
                        'assign the field the value
                        doc.ReplaceItemValue fieldName, fieldValue
                        
                  End If
                  
                  Set el = el.NextSibling
            Loop
            'compute any other required fields here
            'check whether we want to delete an old document and save this one
            doc.Save True, True
      Next
      
      Print "Time taken (DOM): " + Cstr(Timer - startTime)
End Sub


NotesSAXParser Example:

Class CORRSProcessor
      Private db As NotesDatabase
      Private doc As NotesDocument
      Private parser As NotesSAXParser
      Private currentvalue As String
      
      Public Sub New(db As NotesDatabase, xml As NotesStream)
            Set Me.db = db
            Set parser = db.Parent.CreateSAXParser(xml)
            
            On Event SAX_Characters From parser Call SAXCharacters
            On Event SAX_EndDocument From parser Call SAXEndDocument
            On Event SAX_EndElement From parser Call SAXEndElement
            On Event SAX_Error From parser Call SAXError
            On Event SAX_FatalError From parser Call SAXFatalError
            On Event SAX_IgnorableWhitespace From parser Call SAXIgnorableWhitespace
            On Event SAX_NotationDecl From parser Call SAXNotationDecl
            On Event SAX_ProcessingInstruction From parser Call SAXProcessingInstruction
            On Event SAX_StartDocument From parser Call SAXStartDocument
            On Event SAX_StartElement From parser Call SAXStartElement
            On Event SAX_UnparsedEntityDecl From parser Call SAXUnparsedEntityDecl
            On Event SAX_Warning From parser Call SAXWarning
      End Sub
      
      Public Sub Process
            parser.Process
      End Sub
            
      Private Sub SAXStartDocument (Source As Notessaxparser)
            
      End Sub
      
      Private Sub SAXEndDocument (Source As Notessaxparser)
            
      End Sub
      
      Private Sub SAXStartElement (Source As Notessaxparser, Byval elementname As String, Attributes As NotesSaxAttributeList)
            If elementname = "WITExtract" Then
                  'Ignore the document root
            Elseif elementname = "EMPLOYER" Then
                  'Create a new document for each employer
                  Set doc = Me.db.CreateDocument
            Else
                  Me.currentValue = ""
            End If      
      End Sub
      
      Private Sub SAXCharacters (Source As Notessaxparser, Byval Characters As String, Count As Long)
            Me.currentValue = Me.currentValue + Characters
      End Sub
      
      Private Sub SAXEndElement (Source As Notessaxparser, Byval ElementName As String)
            On Error Goto errorh
            
            Dim fieldName As String
            Dim fieldValue As String
            
            If elementname = "WITExtract" Then
                  'Ignore the document root
            Elseif elementname = "EMPLOYER" Then
                  'compute any other required fields here
                  'check whether we want to delete an old document and save this one
                  doc.Save True, True
            Else
                  'transform the element name to the correct field name (probably a select statement)
                  fieldName = elementname
                  
                  'transform the element value to the correct field value
                  fieldValue = Me.currentValue
                                    
                  'assign the field the value
                  doc.ReplaceItemValue fieldName, fieldValue
            End If
            Exit Sub
            
errorh:
            Exit Sub
      End Sub
      
      Private Sub SAXError (Source As Notessaxparser, Exception As NotesSaxException )
            
      End Sub
      
      Private Sub SAXFatalError (Source As Notessaxparser, Exception As NotesSaxException)
            
      End Sub
      
      Private Sub SAXIgnorableWhitespace (Source As Notessaxparser,Byval characters As String, Count As Long)
            
      End Sub
      
      Private Sub SAXNotationDecl (Source As Notessaxparser,Byval NotationName As String, Byval publicid As String, Byval systemid As String)
            
      End Sub
      
      Private Sub SAXProcessingInstruction (Source As Notessaxparser, Byval target As String, Byval PIData As String)
            
      End Sub
      
      Private Sub SAXUnParsedEntityDecl (Source As Notessaxparser, Byval Entityname As String, Byval publicid As String, Byval systemid As String, Byval notationname As String)
            
      End Sub
      
      Private Sub SAXWarning (Source As Notessaxparser, Exception As NotesSaxException)
            
      End Sub
      
End Class

Sub Initialize
      Dim startTime As Single
      startTime = Timer
      
      Dim ses As New NotesSession
      Dim db As NotesDatabase
      Dim xml As NotesStream
      Dim CP As CORRSProcessor
      
      Set db = ses.CurrentDatabase
      
      'Open the XML file
      Set xml = ses.CreateStream
      If Not xml.Open(XML_FILE) Then
            Exit Sub
      End If
      
      Set CP = New CORRSProcessor(db, xml)
      CP.Process
      
      Print "Time taken (SAX): " + Cstr(Timer - startTime)
End Sub
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question