为什么sax解析器给我有限的字符输出?

时间:2015-12-31 00:34:53

标签: java xml-parsing saxparser

我正在使用SAX来解析XML数据。我想提取特定标签的内容。我要提取的包含文本是7-9段,包含近1500个单词。问题是每当我运行我的代码时,我只得到这个文本的两个第一行而不是整个!

我输入的样本是这样的;

<class>
      <page>
        <text xml:space="preserve" bytes="14540">
          this is page 1
          name        = NAME.
          tag         = TAG
          This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.
          ==
          This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.
          ==
          This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.
        </text>
      </page>

      <page>
        <text xml:space="preserve" bytes="2498">
          this is page 2
          name        = NAME.
          tag         = TAG
          This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.
          ==
          This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.
          ==
          This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.
        </text>
      </page>
    </class>

这是我的代码的一部分,用于打印指定标记(文本)的内容;

 public void characters(char ch[],int start, int length) throws SAXException {
      String content = new String(ch, start, length);
        if (btext) {
            System.out.println("Text: " + content);
            btext = false; 
        }
 }

我的结果是这样的;

Start page 1
Text: this is page 1
name        = NAME.
End page
Start page 2
Text: this is page 2
name        = NAME.
End page

我想要一个打印<text> </text>内所有文字的结果,但正如您所看到的那样只是前两行文字。
你能帮我找一个解决方案吗?

0 个答案:

没有答案