Tuesday, December 16, 2008

Oracle XML Pull Parser

The brand new XML Pull Parser is a cool thing. Smaller, than DOM, easier to use, than SAX.

Here's a sample usage:

-- schnipp --

XMLStreamReader reader=XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(eventxml));
while(reader.hasNext()) {
int eventType=reader.next();
if(eventType==XMLEvent.START_ELEMENT && reader.getLocalName().endsWith("Event")){
String localName=reader.getLocalName());

-- schnapp --

To use it with OC4J, you have to register it as a shared library:

1. Add it to your server.xml (along with xmlparserv2):

<shared-library name="xmlpull" version="1.0" library-compatible="true">
<code-source path="C:\...\lib\xmlpull.jar"/>
<code-source path="C:\...\lib\xmlparserv2.jar"/>

2. Add orion-application.xml to your application and configure it to load the library:

<import-shared-library name="xmlpull"></import-shared-library>

No comments:

Post a Comment