P
pgaleas
Hello all,
I'm novice using Jakarta Digester.
I try to parse the folling xml document:
<DOC>
<DOCNO>100</DOCNO>
<TEXT>
text1
</TEXT>
</DOC>
<DOC>
<DOCNO>200</DOCNO>
<TEXT>
text2
</TEXT>
</DOC>
.....but I obtain this error message:
at
org.apache.commons.digester.Digester.createSAXException(Digester.java:2540)
at
org.apache.commons.digester.Digester.createSAXException(Digester.java:2566)
at org.apache.commons.digester.Digester.endElement(Digester.java:1061)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown
Source)
at org.apache.commons.digester.Digester.parse(Digester.java:1532)
..........
Can you help me to find the bug?
THE CODE :
public void digest( File file ) throws IOException, SAXException {
Digester digester = new Digester();
digester.setValidating( false );
digester.addObjectCreate( "DOC", DocumentItem.class );
digester.addBeanPropertySetter( "DOC/DOCNO", "docno" );
digester.addBeanPropertySetter( "DOC/TEXT", "text" );
digester.addSetNext( "DOC", "printDocument" );
/* Parse the document */
doc = (DocumentItem)digester.parse( file );
}
public class DocumentItem {
private String docno;
private String title;
private String text;
public String getDocno() {
return docno;
}
public void setDocno(String docno) {
this.docno = docno;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public void setText(String text) {
this.text = text;
}
public String getText() {
return this.text;
}
public String toString() {
StringBuffer buf = new StringBuffer();
buf.append("itemid >> " + this.getDocno()+"\n");
buf.append("title >> " + this.getTitle()+"\n");
buf.append("text >> " + this.getText());
return buf.toString();
}
public void printDocument() {
this.toString();
}
}
I'm novice using Jakarta Digester.
I try to parse the folling xml document:
<DOC>
<DOCNO>100</DOCNO>
<TEXT>
text1
</TEXT>
</DOC>
<DOC>
<DOCNO>200</DOCNO>
<TEXT>
text2
</TEXT>
</DOC>
.....but I obtain this error message:
at
org.apache.commons.digester.Digester.createSAXException(Digester.java:2540)
at
org.apache.commons.digester.Digester.createSAXException(Digester.java:2566)
at org.apache.commons.digester.Digester.endElement(Digester.java:1061)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown
Source)
at org.apache.commons.digester.Digester.parse(Digester.java:1532)
..........
Can you help me to find the bug?
THE CODE :
public void digest( File file ) throws IOException, SAXException {
Digester digester = new Digester();
digester.setValidating( false );
digester.addObjectCreate( "DOC", DocumentItem.class );
digester.addBeanPropertySetter( "DOC/DOCNO", "docno" );
digester.addBeanPropertySetter( "DOC/TEXT", "text" );
digester.addSetNext( "DOC", "printDocument" );
/* Parse the document */
doc = (DocumentItem)digester.parse( file );
}
public class DocumentItem {
private String docno;
private String title;
private String text;
public String getDocno() {
return docno;
}
public void setDocno(String docno) {
this.docno = docno;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public void setText(String text) {
this.text = text;
}
public String getText() {
return this.text;
}
public String toString() {
StringBuffer buf = new StringBuffer();
buf.append("itemid >> " + this.getDocno()+"\n");
buf.append("title >> " + this.getTitle()+"\n");
buf.append("text >> " + this.getText());
return buf.toString();
}
public void printDocument() {
this.toString();
}
}