Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SAX解析器连接问题_Java_Sax_Saxparser - Fatal编程技术网

Java SAX解析器连接问题

Java SAX解析器连接问题,java,sax,saxparser,Java,Sax,Saxparser,我有一个xml文件,读起来像 <Event Id="258" Key="123456"> <SubEvent Id="1"> Microsoft will begin selling its &quot;Kinect&quot; full-body motion-sensing game system from November 4, while Sony launched its &quot;Move&quot; motion-contr

我有一个xml文件,读起来像

<Event Id="258" Key="123456">
<SubEvent Id="1">
Microsoft will begin selling its &quot;Kinect&quot; full-body motion-sensing game system from November 4, while Sony launched its &quot;Move&quot; 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;
            }
}