JDOM过早结束文件异常?

时间:2011-10-15 03:44:54

标签: java jdom

我想读取与子节点关联的所有CDATA并将它们存储到java ArrayList中!如果您能建议一种简单快捷的方式,我会非常感激它!

在这段代码中,我尝试检查子节点是否有匹配的“txid”属性,并将其下的CDATA存储到ArrayList中。这段代码最初是由“FloppyDisk”建议的,我只是应用了一些修改来适应我的整体代码!

 SAXBuilder builder = new SAXBuilder();
 Document doc = builder.build(in);  //build a JDOM doc from an input stream
 ArrayList<String> queries = new ArrayList<String>();
 Element root = doc.getRootElement();

 Iterator elemIter = root.getDescendants();

 while (elemIter.hasNext()) {
     Element tempElem = (Element) elemIter.next();
     if (root.getChild("ZQueries").getAttributeValue("txid").equals(tempTxid)) {
         String CDATA = tempElem.getChildText("ZQueries");
         queries.add(CDATA);
     } 
 }



Exception in thread "AWT-EventQueue-0" java.security.PrivilegedActionException:
java.security.PrivilegedActionException: org.jdom.input.JDOMParseException: Error on 
line 1: Premature end of file.

AND这是XML结构

 <?xml version="1.0" encoding="utf-8" standalone="yes" ?> 
 <ZQueries txid="Group 1" version="1.0.0.0">
 <ZQuery name="Some Name 1" savename="SomeFileName1.xml">
  <![CDATA[ 
      SELECT ...........

  ]]> 
 </ZQuery>
 <ZQuery name="Some Name 2"   savename="SomeFileName.xml">
 <![CDATA[ 
    SELECT .............


  ]]> 
</ZQuery>
<ZQuery name="some name 3" savename="someFileName.xml">
<![CDATA[ 
    SELECT ..............

 ]]> 
 </ZQuery>
 </ZQueries>
 <ZQueries txid="Group 2" version="1.0.0.0">
 <ZQuery name="Some Name 1" savename="SomeFileName1.xml">
  <![CDATA[ 
      SELECT ...........

  ]]> 
 </ZQuery>
 <ZQuery name="Some Name 2"   savename="SomeFileName.xml">
 <![CDATA[ 
    SELECT .............


  ]]> 

 </ZQueries>

0 个答案:

没有答案