Java を使用して、リモート デバイスによって生成されたイベント ドライブ XML の進行中のストリームを解析しようとしています。2 つのイベントの簡単なサンプルを次に示します。
<?xml version="1.0"?>
<Event> DeviceEventMsg
<Param1>SomeParmValue</Param1>
</Event>
<?xml version="1.0"?>
<Event> DeviceEventMsg
<Param1>SomeParmValue</Param1>
</Event>
DOM よりも SAX の方が適しているように思えます。これは進行中のストリームであるためです。ただし、私は Sax に詳しくありません。XML の構造について怒鳴らないでください。私はそれを既に知っており、変更することはできません。
はい、デバイスはすべてのイベントの前に xml ディレクティブを送信します。私の最初の問題は、2 番目の xml 処理命令が SAX パーサーをクラッキングしていることです。
誰かがそれを回避する方法を提案できますか?
私がこれまで使用していた、2 番目の xml 処理命令で鳴っているコードは次のとおりです。
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 ();
}
}
}