Jakarta Digester...parsing problem

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();
}

}
 
A

Andreas Wollschlaeger

pgaleas said:
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)

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
 
P

pgaleas

Hi Andreas,
I add manually the root element <DOCUMENTS> to the XML File and it
works!
Thank You very much
Greetings
Patricio
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top