Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

Jakarta Digester...parsing problem

Thread view: 
pgaleas - 12 Oct 2006 21:47 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.