我有一个 xml 文件,内容如下
<Event Id="258" Key="123456">
<SubEvent Id="1">
Microsoft will begin selling its "Kinect" full-body motion-sensing game system from November 4, while Sony launched its "Move" motion-controlled gaming system on September 15.
</SubEvent>
</Event>
解析器处理程序的一部分
public void startElement(String uri, String localName,String qName,
Attributes atts) throws SAXException {
if (qName.equalsIgnoreCase("event")) {
scored = false;
event = true;
if (//my condition){
scored = true;
}
if (scored){
sb= new StringBuffer();
}
}
public void characters(char ch[], int start, int length) throws SAXException {
if (event) {
event = false;
}
if (subevent) {
if (scored){
sb.append(new String(ch, start, length));
}
subevent = false;
}
}
但这只会返回“微软将开始销售其”
我读到解析器可能会执行多个字符调用。如何将不同的调用连接在一起?你能解释一下逻辑流程吗?
附加信息:我打印了所有元素,看来句子的其余部分没有被调用,为什么?
Start Element :Event
Start Element :SubEvent
SubEvent:
Microsoft will begin selling its
End Element :SubEvent
End Element :Event
Start Element :Event
Start Element :SubEvent
SubEvent:
Nintendo will sell a new version of its DS handheld device that can play games and show movies in 3D without glasses sometime before March 2011.
End Element :SubEvent
End Element :Event