Archive for the ‘XML’ Category

 
Jun
19
Posted (Johan Känngård) in Java, XML on June-19-2007

Those of you who haven’t used System.out.println(”My variable: ” + myVariable) in some Java classes to get debug information to the console, raise your hands please. None? ;-)

I am very fond of logging as a complement to debugging, since I can “trace” actions in my programs even if the classes is in production. “But hey, logging makes the application go slower!” you might think. Well, it’s up to you to decide, a small performance hit is likely to occur, a big hit if you don’t read the documentation of for instance the PatternLayout.
I use Log4j a lot in the Java code I design and write, and haven’t noticed any big difference between logging and not logging.
So, you might have used Log4j a bit and used Chainsaw to look at Log4j logging files. Why not look at the logging in realtime? Here is how to do it.
Read the rest of this entry »



 
May
25
Posted (Johan Känngård) in Domino/Notes, Fun, Java, XML on May-25-2007

Johan defeating Darth Vader
I was a key speaker at the first g33k date ever yesterday, and it was Ekakan that held the meeting in their small but great office at Saltmätargatan in Stockholm. Quite a lot showed up, many of which I know by name, but not by face, since they are all bloggers with no pictures at their sites! :-) After having slurped down some well-known red-canned sugary liquid, I started my speech using OpenOffice Impress as presenter application. The slides can be found at the bottom of this post. It has not been cleaned up, so some references are to my local file system and applications on my Domino server will not work. I have put the database I used for the web service stuff as an attachment below, but use it at your own risk!
I talked briefly about who I am, what I like, what my shoe size is and other important stuff. A short history on how the web has evolved over time (1.0, 1.5, 2.0) and my own suggestion of the next 3.0 level, which includes web services on the client side. I demonstrated a simple AJAX solution for typeahead with script.aculo.us and Domino and a web service consumer in the browser.
A Midlet with a web service consumer was the next item to show, and it worked as a charm in the emulator!
After my 15 minutes of fame (or rather 40), we had a short drinking and chatting pause.

Joachim Dagerot introduced us into ext.js, a client-side framework with lot’s of goodies like menus, trees, tabbed tables, layouts etc. The framework looked really impressive, and applications based on it was more of a Windows experience. When developing applications with ext.js, almost everything is done in JavaScript, including the templates of the pages. You don’t have to download the complete framework, you can take bits and pieces, if you want only a part of the gadgets.

After more beverages, snacks and more chatting, connections were made, business cards and email addresses exchanged hands. I left rather early though, I hope my fellow bloggers to give the full story ;-) Photos were taking during the meeting, and I would really love to see them, since I didn’t use my own camera.

I hope that this event wasn’t the last of it’s kind in Sweden, it was great fun to see fellow bloggers and geeks!
Thanks for a great event everyone, especially Ekakan who arranged the g33k date!!

Btw, the picture at the top is NOT from the g33k date, it was just a picture I used in the presentation as an illustration of the thin red line between being a geek and a nerd. :-D

Technorati Tags: , , , , ,



 
Feb
13
Posted (Johan Känngård) in Domino/Notes, Java, XML on February-13-2006

Here is an example how to use the XMLEchoer class, that I have refurbished from Sun’s tutorial Echoing an XML File with the SAX Parser. It is of limited use, but can be a good start learning SAX.

import java.io.PrintWriter;
import lotus.domino.AgentBase;
import net.kanngard.xml.XMLEchoer;
 
public class JavaAgent extends AgentBase {
 
    public void NotesMain() {
 
        try {
            String xml = "<test>Hello World</test>";
            PrintWriter writer = getAgentOutput();
            writer.println("Content-type: text/xml");
            XMLEchoer echoer = new XMLEchoer(writer);
            echoer.start(xml);
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
}

To get it working, you need a SAX implementation, like Apache Xerces 2. Just drop the JAR files from Xerces 2 into the jvm/lib/ext directory in your Notes or Domino installation. Restart the http task if you are testing with Domino.

Technorati Tags: , ,



 
Jan
17
Posted (Johan Känngård) in LotusScript, XML on January-17-2006

I am not Microsoft’s biggest fan, since I was a Macintosh fanatic in the old days, but had to convert into the Wintel platform for about 10 years ago. :-) But I have to admit though, when comparing Microsoft’s XML parser with the ones that are built into Notes/Domino, that their products sometimes are great!
When comparing Microsoft’s XML parser with the other two, I created an agent that parsed a big (over 700 KB) and complex XML document and read an element’s value. I did this 25 times per parser, and came up with this interesting result (average execution time per parser) when executed in the Notes client:

  1. Microsoft XML Parser: 0.2 seconds
  2. NotesSAXParser: 2.2 seconds
  3. NotesDOMParser: 2.5 seconds

When executed on a Domino server, the result was a bit different, since the server is a bit old:

  1. Microsoft XML Parser: 1.0 seconds
  2. NotesSAXParser: 5.0 seconds
  3. NotesDOMParser: 7.7 seconds


 
Jan
11
Posted (Johan Känngård) in LotusScript, XML on January-11-2006

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



 
Jan
11
Posted (Johan Känngård) in LotusScript, XML on January-11-2006

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…



 
Dec
16
Posted (Johan Känngård) in LotusScript, XML on December-16-2005

So I don’t forget the next time I want to do this, and trust me, I got a short memory!

Dim xml As String
Dim rootElementNode As NotesDOMElementNode
xml = "YOUR XML HERE"
Set rootElementNode = parseXML(xml)._
getElementsByTagName("THE ROOTNODE").getItem(1)
Public Function parseXML(xml As String) _
As NotesDOMDocumentNode
  ' Parses the specified xml.
  On Error Goto catch
  Dim session As New NotesSession()
  Dim stream As NotesStream
  Set stream = session.createStream()
  Call stream.writeText(xml)
  Dim domparser As NotesDOMParser
  Set domparser = session.createDOMParser(stream)
  domParser.exitOnFirstFatalError = True
  Call domParser.parse()
  Set parseXML = domparser.Document
  Exit Function
catch:
  Error Err, _
Err & "|" & Error & "|" & Lsi_info(2) & ":" & Erl
End Function