Examples: GetItem method

This agent reads the origXML file, walking the tree looking for specific information [refer to the "Attribute values" in the (Declarations) object] in each "Person document." The information is written to reportFile.

(Declarations)
REM Constants found in a Notes names.nsf DXL file:
REM Node names
Const DOCUMENT_NODE_NAME = "document"
Const ITEM_NODE_NAME = "item"
REM Attribute names
Const FORM_ATTR_NAME = "form"
REM Attribute values
Const PERSON = "Person"
Const LASTNAME = "LastName"
Const FIRSTNAME = "FirstName"
Const COMPANY = "CompanyName"
Const JOBTITLE = "JobTitle"
Const OFFICE = "Office"

Dim session As NotesSession
Dim inputStream As NotesStream
Dim outputStream As NotesStream
Dim origXML As String
Dim reportFile As String
Dim NL As String
Sub Initialize
%REM The relevant structure of the .NSF DXL file is:
  <database...>	                     the root element
    <document form="Person">        the "Person document"
      <item name="attribute name">
        <text>text value</text>
      </item>
    </document>
  </database>
%END REM
  
  Dim db As NotesDatabase
  Dim domParser As NotesDOMParser
  Dim rootElement As NotesDOMElementNode    '<database...>
  Dim docList As NotesDOMNodeList     'list of <document> nodes
  Dim itemList As NotesDOMNodeList    'list of <item> nodes
  Dim match As Variant                'used to report on specific data
  Dim eNode As NotesDOMElementNode    'a <document> node
  Dim node As NotesDOMNode            'an <item> node
  Dim aNode As NotesDOMAttributeNode  'a "name" attribute
  Dim text As NotesDOMNode            'the text value
  Dim i As Integer, j As Integer, k As Integer
  
  origXML = "c:\dxl\Contacts.xml"
  reportFile = "c:\dxl\namesDXL.txt"
  NL = Chr(13) + Chr(10)
  
  Set session = New NotesSession    
  If Not createFiles( "Report on Contacts") Then Exit Sub
  Set domParser=session.CreateDOMParser(inputStream)
  domParser.Process
  Set rootElement = domParser.Document.DocumentElement
  
  Set docList = rootElement.GetElementsByTagName (DOCUMENT_NODE_NAME)
  If docList.NumberOfEntries = 0 Then 
    Messagebox "No <document> element nodes in file", , "Error"
    Exit Sub
  End If
  
  REM Report on the DXL file
  For i = 1 To docList.NumberOfEntries
    Set eNode = docList.GetItem(i)
    If eNode.GetAttribute(FORM_ATTR_NAME) = PERSON Then
      outputStream.WriteText(NL)
      For j = 1 To eNode.Attributes.NumberOfEntries
        Set itemList = eNode.GetElementsByTagName (ITEM_NODE_NAME)
        For k = 1 To itemList.NumberOfEntries
          Set node = itemList.GetItem(k)
          Set text = node.FirstChild.FirstChild
          If Not text.IsNull Then
            Set aNode = node.Attributes.GetItem(1)
            match = matchList(aNode.NodeValue)
            If match(0) > 0 Then _
            outputStream.WriteText(aNode.NodeValue+": "+text.NodeValue+NL)
          End If
        Next  '<item> node
      Next  'attribute
    End If
  Next  '<document> node
  
  outputStream.WriteText (NL+"File processed: "+origXML )
  Call outputStream.Close
  Messagebox "Report written to "+reportFile
End Sub

Function createFiles(title As String)
  'create the output file
  Set outputStream = session.CreateStream
  outputStream.Open (reportFile)
  outputStream.Truncate
  outputStream.WriteText (title+NL)
  'open the XML file
  Set inputStream = session.CreateStream
  inputStream.Open (origXML)
  createFiles = Not inputStream.Bytes = 0
End Function

Function matchList(value As String)
  matchList = Evaluate( "@Member (""" + _
  value +  _
  """; """ + _
  FIRSTNAME + _
  """: """ + _
  LASTNAME + _
  """: """ + _
  COMPANY + _
  """: """ + _
  JOBTITLE + _
  """: """ + _
  OFFICE + _
  """)" _
  )
End Function