commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Cooper" <martin.coo...@tumbleweed.com>
Subject RE: Question on getting to the parsed XML
Date Tue, 02 Jul 2002 19:42:20 GMT
This is a question for commons-user, not commons-dev.

You're missing a call to addSetNext() or something similar in your rules
(after the addBeanPropertySetter() calls). With your current code, the
object is being created on the Digester stack, but dropped at the end of the
parse.

--
Martin Cooper

> -----Original Message-----
> From: Brad Jones [mailto:bostitch_21@hotmail.com]
> Sent: Tuesday, July 02, 2002 12:42 PM
> To: commons-dev@jakarta.apache.org
> Subject: Question on getting to the parsed XML
> 
> 
> 
> I am new to XML parsing (from an xml file to a Java object) 
> and I'm trying 
> out Digester. I'm having trouble figuring out how to use the 
> digester to 
> access the parsed XML once i've run the digester.parse() 
> method.  FYI...The 
> following examples are just testing code for me to learn 
> digester so things 
> like Exception handling are not fully written.
> 
> Here's a very simple xml file that I"m parsing:
> 
> 	<toplevel>
> 		<element>
> 			<field1>Value 1</field1>
> 			<field2>Value 2</field2>
> 		</element>
> 	</toplevel>
> 
> Here's my digester code that I'm using to parse the XML show above:
> 
> TestPropertyBean tpbean = new TestPropertyBean();
> java.io.FileInputStream fileInputStream = null;
> Digester digester = new Digester();
> 
> //Adding data structure to digester to be parsed
> digester.push(tpbean);
> 
> digester.setValidating(false);
> 
> //Rules for parsing the xml file.
> digester.addObjectCreate("toplevel/element", 
> "com.ibm.us.force.bean.property.TestPropertyBean");
> digester.addBeanPropertySetter("toplevel/element/field1", "field1");
> digester.addBeanPropertySetter("toplevel/element/field2", "field2");
> 
> try{
> 	fileInputStream = new java.io.FileInputStream("c:/test.xml");
> }catch(java.io.FileNotFoundException fnfe){
> 	//Handle exception for File Not Found
> }
> 
> try{
> 	Object data = digester.parse(fileInputStream);
> 	fileInputStream.close();
> 
> }catch(org.xml.sax.SAXException se){
> 	//Handle exception for sax parser
> 	System.out.println(se.getMessage());
> }catch(java.io.IOException ie){
> 	//Hanlde exception for IO
> }
> 
> When the digester.parse() method is called, I can see the 
> TestPropertyBean 
> setters being called and the values being set to the bean 
> instance.  My 
> problem is that I don't know how to get access to that data 
> once it's been 
> parsed...any suggestions would be greatly appreciated.
> 
> Brad
> 
> 
> _________________________________________________________________
> Chat with friends online, try MSN Messenger: http://messenger.msn.com
> 
> 
> --
> To unsubscribe, e-mail:   
> <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: 
> <mailto:commons-dev-help@jakarta.apache.org>
> 
> 


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message