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();
}
}
Andreas Wollschlaeger - 12 Oct 2006 22:10 GMT
> Hello all,
>
[quoted text clipped - 18 lines]
> at
> org.apache.commons.digester.Digester.createSAXException(Digester.java:2540)
Hi,
given the fragment of input, it's simply not valid XML! (No root element)
In such cases, it's a good idea to check your XML *before* you feed it
to your application! Quite a few friends to help you: Netbeans and
XEMacs have a nice check button, Cooktop is also quite nice, perhaps
quite a few other tools can do...
HTH
Andreas
pgaleas - 13 Oct 2006 18:46 GMT
Hi Andreas,
I add manually the root element <DOCUMENTS> to the XML File and it
works!
Thank You very much
Greetings
Patricio
> > Hello all,
> >
[quoted text clipped - 29 lines]
> HTH
> Andreas