commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From José Antonio Pérez Testa <japte...@indra.es>
Subject Re: [digester] how to parse node trees
Date Thu, 29 Apr 2004 17:51:53 GMT
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: commons-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>  
>

-------------------------------------------------------------------------------------------------------------------
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: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message