Java를 사용하여 원격 장치에서 생성 된 진행중인 이벤트 드라이브 XML 스트림을 구문 분석하려고합니다. 여기에 두 이벤트의 단순화 된 예제이다 : 나는 삭스와 같은 익숙한 아니에요하지만 그것은, 지속적인 스트림이기 때문에 SAX는 DOM에 비해이 더 적합한 것 같다Java에서 "이벤트 XML"을 구문 분석하는 방법은 무엇입니까?
<?xml version="1.0"?>
<Event> DeviceEventMsg
<Param1>SomeParmValue</Param1>
</Event>
<?xml version="1.0"?>
<Event> DeviceEventMsg
<Param1>SomeParmValue</Param1>
</Event>
. XML 구조에 대해 저를 부르짖 지 마십시오. 이미 알고 있으며 변경할 수 없습니다.
그리고 예, 장치는 모든 이벤트 전에 xml 지시어를 보냅니다. 내 첫 번째 문제는 두 번째 xml 처리 명령이 SAX 파서를 왜곡한다는 것입니다.
아무도 그 문제를 해결할 방법을 제안 할 수 있습니까?
두 번째 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();
}
}
}
데이터 스트림은 얼마나 빨리 업데이트됩니까? XML 헤더간에 연결이 끊어 졌습니까? – simon
이벤트는 홈 오토메이션 장치의 켜기/끄기 이벤트이므로 몇 초 간격이 될 수 있지만 길게 활동하지는 않습니다. 이벤트는 연결간에 유지됩니다. –