Java SAX解析器连接问题
我有一个xml文件,读起来像Java SAX解析器连接问题,java,sax,saxparser,Java,Sax,Saxparser,我有一个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-contr
<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>
但这只是返回“微软将开始出售其产品”
我了解到解析器可能会执行多个字符调用。
如何将不同的调用连接在一起?你能解释一下逻辑流程吗
其他信息:
我打印了所有的元素,看起来句子的其余部分没有被调用,为什么
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
字符(char ch[],int start,int length)
方法不读取整行,您应该将字符存储在StringBuffer
中,并在endElement
方法中使用
public void endElement(String uri, String localName, String qName) throws SAXException
{
if (qName.equalsIgnoreCase("event"))
{
System.out.println(sb.toString());
}
sb = new StringBuffer();
}
解决了
public void endElement(String uri, String localName,
String qName) throws SAXException {
if (qName.equalsIgnoreCase("event")) {
scored = false;
}
if (qName.equalsIgnoreCase("subevent")){
subevent=false;
}
}
请查看我的其他信息。Sax也不会打印行的其他部分,但会立即跳转到下一个事件
public void endElement(String uri, String localName,
String qName) throws SAXException {
if (qName.equalsIgnoreCase("event")) {
scored = false;
}
if (qName.equalsIgnoreCase("subevent")){
subevent=false;
}
}