commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Juergen Weber <webe...@yahoo.com>
Subject [digester] how to parse node trees
Date Thu, 29 Apr 2004 17:31:20 GMT
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.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


Mime
View raw message