Hi Juergen,
apart from corrections donwside, you have to push an object to the Digester stack in order to have something to return when
the parsing of the xml ends.
That is because the SetNext rule pops the element from the stack, so if you start up with nothing you end up with nothing.


Simon surely could give a better explanation but i think that is the basic idea!


Juergen Weber wrote:


Hi,

I want to parse an xml for this dtd


<!ELEMENT node (node*) > <!ELEMENT node (#PCDATA) > <!ATTLIST node type CDATA "name">

like

<?xml version="1.0" encoding="iso-8859-1"?>

<!DOCTYPE node SYSTEM "tree.dtd">
<node name="Impulsdefinitionen">
        <node name="a">
                <node name="b">
                        <node name="c">
                                <node name="d">
                                </node>
                        </node>
                        <node name="e">
                        </node>
                </node>
        </node>
</node>

I tried

Digester digester = new Digester();
digester.setValidating(false);


//digester.addObjectCreate("node",Node.class);
digester.addObjectCreate("*/node",Node.class);
digester.|addSetProperties(|"*/node",|"name"||, "name");|

digester.addSetNext("*/node", "addNode");

InputSource inputSource = new InputSource(xmlfile);

inputSource.setSystemId(dtdfile.toString());

return digester.parse(inputSource);

but this failed with

29.04.2004 19:22:09
org.apache.commons.digester.Digester peek
WARNUNG: Empty stack (returning null)
29.04.2004 19:22:09
org.apache.commons.digester.Digester endElement
SCHWERWIEGEND: End event threw exception
java.lang.NullPointerException
        at
org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:245)
        
        
        
What did I forget?

Node is

public class Node
{
        List l = new ArrayList();
        String name;
        
        public void addNode(Node node)
        {
                l.add(node);
        }
        
        public Iterator getNodes()
        {
                return l.iterator();
        }
        
        public String getName()
        {
                return name;
        }
        
   public void setName(String name)
        {
                this.name = name;
        }
}

Thanks, Juergen





__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs http://hotjobs.sweepstakes.yahoo.com/careermakeover


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




------------------------------------------------------------------------------------------------------------------- Este correo electr�nico y, en su caso, cualquier fichero anexo al mismo, contiene informaci�n de car�cter confidencial exclusivamente dirigida a su destinatario o destinatarios. Queda prohibida su divulgaci�n, copia o distribuci�n a terceros sin la previa autorizaci�n escrita de Indra. En el caso de haber recibido este correo electr�nico por error, se ruega notificar inmediatamente esta circunstancia mediante reenv�o a la direcci�n electr�nica del remitente.

The information in this e-mail and in any attachments is confidential and solely for the attention and use of the named addressee(s). You are hereby notified that any dissemination, distribution or copy of this communication is prohibited without the prior written consent of Indra. If you have received this communication in error, please, notify the sender by reply e-mail

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to