Quantcast
Channel: Johan Känngård » Java
Viewing all articles
Browse latest Browse all 9

Echo XML from a file, String or InputStream in Java with SAX

$
0
0

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 = "Hello World";
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.

[tags]Java, XML, SAX[/tags]


Viewing all articles
Browse latest Browse all 9

Trending Articles