Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Parsing "Event XML" in Java?
    text
    copied!<p>I'm looking to use Java to parse an ongoing stream of event drive XML generated by a remote device. Here's a simplified sample of two events:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;Event&gt; DeviceEventMsg &lt;Param1&gt;SomeParmValue&lt;/Param1&gt; &lt;/Event&gt; &lt;?xml version="1.0"?&gt; &lt;Event&gt; DeviceEventMsg &lt;Param1&gt;SomeParmValue&lt;/Param1&gt; &lt;/Event&gt; </code></pre> <p>It seems like SAX is more suited to this than DOM because it is an ongoing stream, though I'm not as familiar with Sax. Don't yell at me for the structure of the XML - I know it already and can't change it. </p> <p>And yes the device DOES send the xml directive before every event. My first problem is that the second xml processing instruction is croaking the SAX parser. </p> <p>Can anyone suggest a way to get around that?</p> <hr> <p>The code I'm using so far which is croaking on the second xml processing instruction is:</p> <pre><code>public class TestMe extends HandlerBase { public void startDocument () throws SAXException { System.out.println("got startDocument"); } public void endDocument () throws SAXException { System.out.println("got endDocument"); } public void startElement (String name, AttributeList attrs) throws SAXException { System.out.println("got startElement"); } public void endElement (String name) throws SAXException { System.out.println("got endElement"); } public void characters (char buf [], int offset, int len) throws SAXException { System.out.println("found characters"); } public void processingInstruction (String target, String data) throws SAXException { System.out.println("got processingInstruction"); } public static void main(String[] args) { SAXParserFactory factory = SAXParserFactory.newInstance(); try { SAXParser saxParser = factory.newSAXParser(); // using a file as test input for now saxParser.parse( new File("devmodule.xml"), new TestMe() ); } catch (Throwable err) { err.printStackTrace (); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload