Jan
11
Posted on 11-01-2006
Filed Under (LotusScript, XML) by Johan Känngård

In my earlier post today, I described a problem I have, where I wanted to get the XML string of a DOM tree. I’ve started writing my own routine, this is what I have right now. It’s far from complete, since it can not handle namespaces, CDATA etc. yet:
This is a new version that handles siblings better, and not getting out of stack space :-)


Public Sub serializeNode(node As NotesDOMNode_
, outStream As NotesStream)
  On Error Goto catch
  
  If node.IsNull Then Exit Sub
  
  Dim currentNode As NotesDOMNode
  Set currentNode = node
  
  Do Until currentNode.isNull
    Select Case currentNode.nodeType
    Case DOMNODETYPE_DOCUMENT_NODE
    Case DOMNODETYPE_XMLDECL_NODE
      Dim xmlDecl As NotesDOMXMLDeclNode
      Set xmlDecl = currentNode
      Call outStream.WriteText("< ?xml version=""" _
+ xmlDecl.version + """ encoding=""" + xmldecl.encoding + """?>")
    Case DOMNODETYPE_ELEMENT_NODE
      Call outStream.writeText("< " + currentNode.nodeName + "")
      Dim nodeMap As NotesDOMNamedNodeMap
      Set nodeMap = currentNode.attributes
      Dim attribute As NotesDOMNode
      Dim i As Integer
      
      For i = 1 To nodeMap.numberOfEntries
        Set attribute = nodeMap.getItem(i)
        Call outStream.WriteText(" " + attribute.nodeName + "=")
        Call outStream.WriteText("""" + attribute.NodeValue + """")
      Next i
      Call outStream.writeText(">")
    Case DOMNODETYPE_TEXT_NODE
      Call outStream.writeText(currentNode.NodeValue)
    Case DOMNODETYPE_COMMENT_NODE
      Call outStream.writeText("<!--" _
+ currentNode.NodeValue + "-->")
    Case Else
      Error 2000, "Unhandled node type [" _
& currentNode.nodeType & "]"
    End Select
    
    Dim endWritten As Boolean
    
    If currentNode.hasChildNodes Then
      Call serializenode(currentNode.firstChild, outStream)
    End If
    
    If currentNode.NodeType = DOMNODETYPE_ELEMENT_NODE Then
      Call outStream.writeText("")
      endWritten = True
    End If
    
    Set currentNode = currentNode.nextSibling
  Loop
  
  If node.NodeType = DOMNODETYPE_ELEMENT_NODE _
And Not endWritten Then
    Call outStream.writeText("")
  End If
  Exit Sub
catch:
  Error Err, Err & Lsi_Info(2) & ":" & Erl & "|" & Error
End Sub

(2) Comments    Read More   
Jan
11
Posted on 11-01-2006
Filed Under (LotusScript, XML) by Johan Känngård

I have a problem, that nor I nor any of my colleagues can’t solve easily. I have several classes that are passing objects/variables between them. On of them is handling Web Service request, and parsing the responses to a NotesDOMDocumentNode via the NotesDOMParser. The NotesDOMDocumentNode is passed returned, and are used in several places to extract information. But, I need to cache the response, so concurrent request with the same parameters are sped up.
To cache the response, I need to serialize the NotesDOMDocumentNode. At first, I thought this was easy, since there is a Serialize method on the NotesDOMParser. But no… You have to keep the original NotesDOMParser that parsed the raw XML data. The only solutions I can figure out are:

  • pass both the NotesDOMDocumentNode AND the original NotesDOMParser at all times
  • write my own Serialize method
  • pass the XML string only, and do the parsing at each method. I think this would be really slow…

To further illustrate what I want, here is an example:


Public Sub testDOMParser()
  Dim parser As NotesDOMParser
  Dim inStream As NotesStream
  Dim node As NotesDOMDocumentNode
  Set inStream = session.createStream()
  Call inStream.open("c:\temp\test.xml")
  Set parser = session.createDOMParser(inStream)
  Call parser.process()
  Set node = parser.document
  Call serializeDocument(node)
End Sub
Public Sub serializeDocument(node As NotesDOMDocumentNode)
  ' Here, I want to do something like this:
  Dim outStream As NotesStream
  Dim parser As NotesDOMParser
  Set outStream = session.createStream()
  Set parser = session.createDOMParser(node, outStream)
  parser.exitOnFirstFatalError = True
  Call parser.serialize()
  Print "Serialized tree: " + outStream.readText()
End Sub

Anyone who have had any experience with this and are willing to share their thoughts? We are talking R6 here…

(5) Comments    Read More   
Jan
11
Posted on 11-01-2006
Filed Under (PC Modding) by Johan Känngård

Inside my home PC

A shot of my home PC with comments after I modified it.

(2) Comments    Read More