commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Marco.Mistr...@nokia.com>
Subject RE: error when using XML rules /2 -> how to retrieve attributes with XML rules
Date Sat, 19 Apr 2003 07:43:23 GMT
hi,
	i tracked down the error..
problem is that with below rule syntax, my XML should be written like

<properties>
  <property>
    <name>aaa</name>
    <value>bbb</value>
  </property>
</properties>

so what i am missing is how to write a rule so that it retrieves
attributes of an XML element..

anyone can help?

thanx in advance and regards
	marco

> -----Original Message-----
> From: Mistroni Marco (NET-IMN/Espoo) 
> Sent: 19 April, 2003 10:30
> To: 'commons-user@jakarta.apache.org'
> Subject: error when using XML rules
> 
> 
> hi all,
> 	i am trying to get digester parse an XML file by defining
> rules in an XML file...
> here is my property file:
> 
> <?xml version="1.0"?>
> <properties>
>     <property name="jco.client.client" value="005"/>
>     <property name="jco.client.user" value="WEBLINKTEST"/>
>     <property name="jco.client.passwd" value="ORANGE"/>
>     <property name="jco.client.ashost" value="sad03dc.nmp.nokia.com"/>
>     <property name="jco.client.sysnr" value="00"/>
>     <property name="jco.pool.name" value="jayco"/>
>     <property name="jco.pool.maxpoolsize" value="51"/>
>     <property name="jco.pool.ticket" value="123"/>
> </properties>
> 
> 
> and here is the rule file
> 
> <?xml version="1.0"?>
> 
> <digester-rules>
> 
>   <!-- Application NamingResources -->
>   <pattern value="properties">
> 
>     <!-- instantiate the root XML element, properties-->
>     <object-create-rule classname="java.util.Properties" />
> 
>       <!-- parameter are defined within the properties" -->
>       <pattern value="property">
> 
>         <!-- map the parameters elements to the properties-->
>         <call-method-rule methodname="setProperty" paramcount="2" />
>         <call-param-rule  pattern="name"  paramnumber="0" />
>         <call-param-rule  pattern="value" paramnumber="1" />
>       </pattern>
> 
>      </pattern>
>   </digester-rules> 
> 
> and i m getting following exception...
> 
> java.lang.reflect.InvocationTargetException: 
> java.lang.NullPointerException
>         at java.util.Hashtable.put(Hashtable.java:375)
>         at java.util.Properties.setProperty(Properties.java:97)
>         at java.lang.reflect.Method.invoke(Native Method)
>         at 
> org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.jav
> a:252)
>         at 
> org.apache.commons.digester.CallMethodRule.end(CallMethodRule.java:49
> 9)
>         at org.apache.commons.digester.Rule.end(Rule.java:276)
>         at 
> org.apache.commons.digester.Digester.endElement(Digester.java:1064)
>         at 
> org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source
> )
>         at 
> org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unkn
> own Source)
>         at 
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElemen
> t(Unknown Source)
>         at 
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContent
> Dispatcher.dispatch(Unknown Source)
>         at 
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Un
> known Source)
>         at 
> org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
>         at 
> org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
>         at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
>         at 
> org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
>         at 
> org.apache.commons.digester.Digester.parse(Digester.java:1527)
>         at XMLDigesterTest.doWork(XMLDigesterTest.java:21)
>         at XMLDigesterTest.main(XMLDigesterTest.java:36)
> [ERROR] Digester - -End event threw exception 
> <java.lang.reflect.InvocationTarge
> tException>
> Exception in thread "main" java.lang.NullPointerException
>         at 
> org.apache.commons.digester.Digester.createSAXException(Digester.java
> :2383)
>         at 
> org.apache.commons.digester.Digester.createSAXException(Digester.java
> :2409)
>         at 
> org.apache.commons.digester.Digester.endElement(Digester.java:1067)
>         at 
> org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source
> )
>         at 
> org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unkn
> own Source)
>         at 
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElemen
> t(Unknown Source)
>         at 
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContent
> Dispatcher.dispatch(Unknown Source)
>         at 
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Un
> known Source)
>         at 
> org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
>         at 
> org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
>         at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
>         at 
> org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
>         at 
> org.apache.commons.digester.Digester.parse(Digester.java:1527)
>         at XMLDigesterTest.doWork(XMLDigesterTest.java:21)
>         at XMLDigesterTest.main(XMLDigesterTest.java:36)
> 
> 
> from my pow, it looks like i am setting properties with 
> name/value  null, null, so
> with the rule file that i have written, digester does not get 
> the value of the
> name and value attributes of the <property> element..
> 
> can anyone tell me how to correct my rulefile or how to fix 
> my problem?
> 
> regards
> 	marco
> 
> 
> 
> 
> > -----Original Message-----
> > From: ext Lafredo, Stephen [mailto:stephen_lafredo@merck.com]
> > Sent: 18 April, 2003 21:36
> > To: Mistroni Marco (NET-IMN/Espoo)
> > Subject: RE: defining rules in XML
> > 
> > 
> > Marco,
> > 
> > I do not have a lot of experiencing writing rules files. 
> > Therefore, I am not
> > up on all of the syntax.
> > 
> > That said this is how I would have written the rules file.
> > 
> > <digester-rules>
> > 
> >   <!-- Application NamingResources -->
> >   <pattern value="jcoproperties">
> > 
> >     <!-- instantiate the root XML element, jcoproperties-->
> >     <object-create-rule
> >       classname="java.util.Properties" />
> > 
> >       <!-- parameter are defined within the jcoproperties" -->
> >       <pattern value="parameter">
> > 
> >         <!-- map the parameters elements to the jcoproperties-->
> >         <call-method-rule methodname="setProperty" paramcount="2" />
> >         <call-param-rule  pattern="name"  paramnumber="0" />
> >         <call-param-rule  pattern="value" paramnumber="1" />
> >       </pattern>
> > 
> >      </pattern>
> >   </digester-rules> 
> > 
> > Using your syntax, I would try modifing the property pattern, e.g.
> > 
> >   <digester-rules>
> >      <object-create-rule pattern="jcoproperties"
> >                        classname="java.util.Properties" />
> > 
> >      <pattern value="property">
> >  	<call-method-rule  methodname="setProperty" paramcount="2" />
> >         <call-param-rule pattern="name" paramnumber="0"/>
> >         <call-param-rule pattern="value" paramnumber="1"/>        
> >      </pattern>
> >   </digester-rules> 
> > 
> > Let me know, what you learn.
> > 
> > Thanks.
> > 
> > Stephen Lafredo
> > Merck & Co., Inc.
> > USHH IS Application Architecture, WP97-A315
> > V: (215) 652-2668
> > E: stephen_lafredo@merck.com
> > 
> > 
> > -----Original Message-----
> > From: Marco.Mistroni@nokia.com [mailto:Marco.Mistroni@nokia.com] 
> > Sent: Friday, April 18, 2003 9:47 AM
> > To: stephen_lafredo@merck.com
> > Subject: RE: defining rules in XML
> > 
> > 
> > Hi Stephen,
> > 	thanx...i have tried...but still no luck...
> > can u tell me what's wrong with my rules file?
> > 
> > i attach all 3 files (normal xml, rules plus the javacode)..
> > 
> > hope i m not bothering u too much :-(
> > 
> > regards
> > 	marco
> > 
> > 
> > > -----Original Message-----
> > > From: ext Lafredo, Stephen [mailto:stephen_lafredo@merck.com]
> > > Sent: 18 April, 2003 16:32
> > > To: Mistroni Marco (NET-IMN/Espoo)
> > > Cc: 'Jakarta Commons Users List'
> > > Subject: RE: defining rules in XML
> > > 
> > > 
> > > Hello,
> > > 
> > > I believe this is what you want.
> > > 
> > >       <!-- parameter are defined within the ResourceParams" -->
> > >       <pattern value="parameter">
> > > 
> > >         <!-- map the parameters elements to the ResourceParams -->
> > >         <call-method-rule methodname="addParameter" 
> > paramcount="2" />
> > >         <call-param-rule  pattern="name"  paramnumber="0" />
> > >         <call-param-rule  pattern="value" paramnumber="1" />
> > >       </pattern>
> > > 
> > > HTH.
> > > 
> > > Stephen Lafredo
> > > Merck & Co., Inc.
> > > USHH IS Application Architecture, WP97-A315
> > > V: (215) 652-2668
> > > E: stephen_lafredo@merck.com
> > > 
> > > 
> > > -----Original Message-----
> > > From: Marco.Mistroni@nokia.com [mailto:Marco.Mistroni@nokia.com]
> > > Sent: Friday, April 18, 2003 8:57 AM
> > > To: commons-user@jakarta.apache.org
> > > Subject: defining rules in XML
> > > 
> > > 
> > > hi all,	
> > > 	 i have following XML file
> > > 
> > > <myproperties>
> > >   <property name="foo" value="bar"/>
> > >   <property name="foo2" value="bar2"/>
> > >   ....
> > > </myproperties>
> > > 
> > > and i would like digester to populate a java.util.Properties
> > > object while
> > > parsing, using an XML rule file
> > > 
> > > but, i m stuck in how to write the proper rule...
> > > i have written followign but seems not to work....
> > > 
> > > <?xml version="1.0"?>
> > >   <digester-rules>
> > >      
> > >      
> > >      <object-create-rule pattern="myproperties" 
> > > classname="java.util.Properties" />
> > > 
> > >      <pattern value="properties/property">
> > >         
> > >         
> > > 	<!??????? <call-method-rule  pattern="name"
> > > methodname="setProperty"
> > > paramcount="2" /> -->        
> > >         
> > >    
> > >      </pattern>
> > > 
> > >     
> > > 
> > >   </digester-rules>
> > > 
> > > i don't know how to write properly the 'call method rule'....
> > > 
> > > anyone can help me?
> > > 
> > > br
> > > 	marco
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > > -----Original Message-----
> > > > From: ext Baltz, Kenneth [mailto:Kbaltz@firstam.com]
> > > > Sent: 13 February, 2003 18:50
> > > > To: Jakarta Commons Users List
> > > > Subject: RE: Digester question
> > > > 
> > > > 
> > > > > 
> > > > > 
> > > > > Is it possible to handle duplicate elements in commons
> > > > digester using
> > > > > the following example ?
> > > > 
> > > > Yes.  Digester will fire whatever rules you assign to the given 
> > > > element as many times as that element appears.
> > > > 
> > > > > 
> > > > > 
> > > > > <phonebook>
> > > > > 	<entry>
> > > > > 	 <owner>Owner</owner>
> > > > > 	 <number>Number</number>
> > > > > 	 [ and many other numbers to follow..]
> > > > > 	 </entry>
> > > > > </phonebook>
> > > > > 
> > > > > I can handle many <entry> elements but can't quite yet 
> > grasp how 
> > > > > to do the multiple number elements. Does anyone have 
> > any idea how
> > > > > to do this ?
> > > > 
> > > > It depends on what you want to do with these elements. 
> > Originally I 
> > > > was going to say that you handle <number> exactly the way you
> > > > handle <entry>,
> > > > there's no difference.  Give us a description of what you 
> > > > would like to have
> > > > happen and we can tell you how to do it. 
> > > > 
> > > > I'm guessing that you have something like an Entry bean,
> > > with an owner
> > > > property and a numbers property that returns a 
> collection. If you 
> > > > have a method addNumber() in your Entry bean, then just use a
> > > > SetNextRule() to call
> > > > addNumber and pass the contents of each <number> to your 
> > Entry bean.
> > > > 
> > > > K.C.
> > > > 
> > > 
> > > 
> > 
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: 
> commons-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: 
> > commons-user-help@jakarta.apache.org
> > > 
> > > 
> > > --------------------------------------------------------------
> > > ----------------
> > > Notice: This e-mail message, together with any attachments,
> > > contains information of Merck & Co., Inc. (Whitehouse 
> > > Station, New Jersey, USA) that may be confidential, 
> > > proprietary copyrighted and/or legally privileged, and is 
> > > intended solely for the use of the individual or entity named 
> > > on this message. If you are not the intended recipient, and 
> > > have received this message in error, please immediately 
> > > return this by e-mail and then delete it.
> > > 
> > > ==============================================================
> > > ================
> > > 
> > > 
> > 
> > --------------------------------------------------------------
> > ----------------
> > Notice: This e-mail message, together with any attachments, 
> > contains information of Merck & Co., Inc. (Whitehouse 
> > Station, New Jersey, USA) that may be confidential, 
> > proprietary copyrighted and/or legally privileged, and is 
> > intended solely for the use of the individual or entity named 
> > on this message. If you are not the intended recipient, and 
> > have received this message in error, please immediately 
> > return this by e-mail and then delete it.
> > 
> > ==============================================================
> > ================
> > 
> > 
> 

Mime
View raw message