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 --

System.setProperty("javax.xml.stream.XMLInputFactory","oracle.xml.stream.OracleXMLInputFactory");
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());
reader.next();
}

-- 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"/>
</shared-library>

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

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

No comments:

Post a Comment