You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Juan Alvarado <ja...@duocash.com> on 2003/12/22 23:45:49 UTC
Digester Question
Hello:
I am relatively new to xml parsing and I just started using the
commons-digester tools and it seems like it might fit my needs.
First let me apologize to all you seasoned pros in the field of XML in
the event that my question seems too simple or if I am just not using
the right terminology.
My question is as follows.
The particular XML that I am working with and in need to parse is
composed as follows:
<?xml version="1.0"?>
<IDTDebitInterface>
<UserInfo>
<username>Juan</username>
<password>Alvarado</password>
</UserInfo>
<DebitRequests ReportSuccesses="true">
<DebitRequest id="1" type="misctrans">
<account>123</account>
<amount>10</amount>
<transtype>vendordebit</transtype>
<note>Test</note>
<balancetozero>n</balancetozero>
</DebitRequest>
</DebitRequests>
</IDTDebitInterface>
As you can see, the node <DebitRequests ReportSuccesses="true">
contains an attribute ReportSuccesses="true". I need to be able to grab
that value so that it can be populated into my corresponding bean.
Additionally there might be times when there is more than one attribute
in a given node and obviously I would need to get those values also.
Could someone please tell me if this is possible and if so, how to
accomplish this.
NEXT QUESTION:
My application not only has to parse this XML stream, but we also have
to create this XML from in certain situations. We might for example
receive a request through the web with the necessary parameters and
values needed to construct the XML and then pass on to the next layer.
Can anyone tell me if the digester framework can handle this and if so,
I'd appreciate some sample code.
Thanks in advance.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: Digester Question
Posted by Juan Alvarado <ja...@duocash.com>.
Ok thanks for the help.
On Dec 22, 2003, at 6:25 PM, Simon Kitching wrote:
> On Tue, 2003-12-23 at 12:18, Juan Alvarado wrote:
>> Simon thanks for all of your help and comments.
>>
>> Off the top of your head can you tell me what tools you have used if
>> any that will allow me to convert from object to xml.
>
> I've never needed to do object->xml, but I know of the following
> projects:
>
> * JAXB
> * Castor
> * java 1.4's "long term bean serialization" (see java.beans.*).
> * Betwixt
>
> Try searching google for "java xml binding" and "java xml
> serialization".
>
> Regards,
>
> Simon
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: Digester Question
Posted by Simon Kitching <si...@ecnetwork.co.nz>.
On Tue, 2003-12-23 at 12:18, Juan Alvarado wrote:
> Simon thanks for all of your help and comments.
>
> Off the top of your head can you tell me what tools you have used if
> any that will allow me to convert from object to xml.
I've never needed to do object->xml, but I know of the following
projects:
* JAXB
* Castor
* java 1.4's "long term bean serialization" (see java.beans.*).
* Betwixt
Try searching google for "java xml binding" and "java xml
serialization".
Regards,
Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [Digester] code must be in static method?
Posted by di...@multitask.com.au.
Got a reason why it 'doesn't work'?
I've successfully used Digester from non static methods several times.
--
dIon Gillard, Multitask Consulting
Blog: http://blogs.codehaus.org/people/dion/
Mike Zatko <za...@comcast.net> wrote on 23/12/2003 12:00:54 PM:
> Howdy,
> I just started looking into the Digester components and I have come
> across a peculiarity as follows. I began by using a precanned example of
> using Digester off of an article on IBM's site I think. Basically, all
> of the Digester code occurrs in the static main method. For my
> particular app, I didn't want this and wanted to do my Digester code
> inside an instantiated object. But, it doesn't work. All it was was a
> simple copy and paste of code from a static main method to inside a
> method of a class inside the same package as before. Why is this?
>
> Here is the code. The first code example works. The second one doesn't.
>
>
> public class ConfigParser
> {
> /**
> * Prints the contact information to standard output.
> *
> * @param contact the <code>Contact</code> to print out
> */
> public void addDatabase(Database database)
> {
> System.out.println("URL: " + database.getUrl());
> System.out.println("Driver: " + database.getDriver());
> System.out.println("User Name: " + database.getUserName());
> System.out.println("Password: " + database.getPassword());
> }
>
> public void addTable(Table table)
> {
> System.out.println("Name: " + table.getName());
> System.out.println("File: " + table.getFile());
> }
>
> /**
> * Configures Digester rules and actions, parses the XML file
specified
> * as the first argument.
> *
> * @param args command line arguments
> */
> public static void main(String[] args)
> {
> try {
> // instantiate Digester and disable XML validation
> Digester digester = new Digester();
> digester.setValidating(false);
>
> // instantiate AddressBookParser class
> digester.addObjectCreate("configuration",
ConfigParser.class);
> // instantiate Contact class
> digester.addObjectCreate("configuration/database",
> Database.class );
>
> // set type property of Contact instance when 'type'
> attribute is found
> //digester.addSetProperties("configuration/contact",
> "type", "type" );
>
> // set different properties of Contact instance using
> specified methods
> digester.addCallMethod("configuration/database/url",
> "setUrl", 0);
> digester.addCallMethod("configuration/database/driver",
> "setDriver", 0);
> digester.addCallMethod("configuration/database/user-name",
> "setUserName", 0);
> digester.addCallMethod("configuration/database/password",
> "setPassword", 0);
>
> // call 'addContact' method when the next
> 'address-book/contact' pattern is seen
> digester.addSetNext("configuration/database",
"addDatabase");
>
>
> digester.addObjectCreate("configuration/table", Table.class
);
> digester.addSetProperties("configuration/table", "name",
> "name");
> digester.addCallMethod("configuration/table/backup-file",
> "setFile", 0);
> digester.addSetNext("configuration/table", "addTable");
>
> // now that rules and actions are configured, start the
> parsing process
> ConfigParser abp = (ConfigParser)digester.parse(new
> File("config-digest.xml"));
>
>
> ConfigParser configParser = new ConfigParser();
> }
> catch (Exception e)
> {
> e.printStackTrace();
> }
> }
> }
>
>
>
>
>
>
> Second one:
>
> public class ConfigParser
> {
> public ConfigParser() throws IOException, SAXException
> {
> // instantiate Digester and disable XML validation
> Digester digester = new Digester();
> digester.setValidating(false);
>
> // instantiate AddressBookParser class
> digester.addObjectCreate("configuration", ConfigParser.class);
> // instantiate Contact class
> digester.addObjectCreate("configuration/database",
Database.class );
>
> // set type property of Contact instance when 'type' attribute
> is found
> //digester.addSetProperties("configuration/contact",
> "type", "type" );
>
> // set different properties of Contact instance using specified
> methods
> digester.addCallMethod("configuration/database/url", "setUrl",
0);
> digester.addCallMethod("configuration/database/driver",
> "setDriver", 0);
> digester.addCallMethod("configuration/database/user-name",
> "setUserName", 0);
> digester.addCallMethod("configuration/database/password",
> "setPassword", 0);
>
> // call 'addContact' method when the next 'address-book/contact'
> pattern is seen
> digester.addSetNext("configuration/database", "addDatabase");
>
>
> digester.addObjectCreate("configuration/table", Table.class );
> digester.addSetProperties("configuration/table", "name",
"name");
> digester.addCallMethod("configuration/table/backup-file",
> "setFile", 0);
> digester.addSetNext("configuration/table", "addTable");
>
> // now that rules and actions are configured, start the parsing
> process
> ConfigParser abp = (ConfigParser)digester.parse(new
> File("config-digest.xml"));
> }
>
> /**
> * Prints the contact information to standard output.
> *
> * @param contact the <code>Contact</code> to print out
> */
> public void addDatabase(Database database)
> {
> System.out.println("URL: " + database.getUrl());
> System.out.println("Driver: " + database.getDriver());
> System.out.println("User Name: " + database.getUserName());
> System.out.println("Password: " + database.getPassword());
> }
>
> public void addTable(Table table)
> {
> System.out.println("Name: " + table.getName());
> System.out.println("File: " + table.getFile());
> }
>
> /**
> * Configures Digester rules and actions, parses the XML file
specified
> * as the first argument.
> *
> * @param args command line arguments
> */
> public static void main(String[] args)
> {
> try {
> ConfigParser configParser = new ConfigParser();
> }
> catch (Exception e)
> {
> e.printStackTrace();
> }
> }
> }
>
>
> Thanks,
> Mike Zatko
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [Digester] code must be in static method?
Posted by Mike Zatko <za...@comcast.net>.
I completely missed that. Thanks.
Simon Kitching wrote:
>On Tue, 2003-12-23 at 14:00, Mike Zatko wrote:
>
>
>>Howdy,
>> I just started looking into the Digester components and I have come
>>across a peculiarity as follows. I began by using a precanned example of
>>using Digester off of an article on IBM's site I think. Basically, all
>>of the Digester code occurrs in the static main method. For my
>>particular app, I didn't want this and wanted to do my Digester code
>>inside an instantiated object. But, it doesn't work. All it was was a
>>simple copy and paste of code from a static main method to inside a
>>method of a class inside the same package as before. Why is this?
>>
>>
>
>Digester is fine. The problem is that you attempt to do all your parsing
>in the *constructor* of a ConfigParser object. One of the rules is:
> digester.addObjectCreate("configuration", ConfigParser.class)
>which creates a new ConfigParser instance - and runs its constructor.
>
>Result: infinite recursion.
>
>Restructure your code and all should be well.
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [Digester] code must be in static method?
Posted by Simon Kitching <si...@ecnetwork.co.nz>.
On Tue, 2003-12-23 at 14:00, Mike Zatko wrote:
> Howdy,
> I just started looking into the Digester components and I have come
> across a peculiarity as follows. I began by using a precanned example of
> using Digester off of an article on IBM's site I think. Basically, all
> of the Digester code occurrs in the static main method. For my
> particular app, I didn't want this and wanted to do my Digester code
> inside an instantiated object. But, it doesn't work. All it was was a
> simple copy and paste of code from a static main method to inside a
> method of a class inside the same package as before. Why is this?
Digester is fine. The problem is that you attempt to do all your parsing
in the *constructor* of a ConfigParser object. One of the rules is:
digester.addObjectCreate("configuration", ConfigParser.class)
which creates a new ConfigParser instance - and runs its constructor.
Result: infinite recursion.
Restructure your code and all should be well.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
[Digester] code must be in static method?
Posted by Mike Zatko <za...@comcast.net>.
Howdy,
I just started looking into the Digester components and I have come
across a peculiarity as follows. I began by using a precanned example of
using Digester off of an article on IBM's site I think. Basically, all
of the Digester code occurrs in the static main method. For my
particular app, I didn't want this and wanted to do my Digester code
inside an instantiated object. But, it doesn't work. All it was was a
simple copy and paste of code from a static main method to inside a
method of a class inside the same package as before. Why is this?
Here is the code. The first code example works. The second one doesn't.
public class ConfigParser
{
/**
* Prints the contact information to standard output.
*
* @param contact the <code>Contact</code> to print out
*/
public void addDatabase(Database database)
{
System.out.println("URL: " + database.getUrl());
System.out.println("Driver: " + database.getDriver());
System.out.println("User Name: " + database.getUserName());
System.out.println("Password: " + database.getPassword());
}
public void addTable(Table table)
{
System.out.println("Name: " + table.getName());
System.out.println("File: " + table.getFile());
}
/**
* Configures Digester rules and actions, parses the XML file specified
* as the first argument.
*
* @param args command line arguments
*/
public static void main(String[] args)
{
try {
// instantiate Digester and disable XML validation
Digester digester = new Digester();
digester.setValidating(false);
// instantiate AddressBookParser class
digester.addObjectCreate("configuration", ConfigParser.class);
// instantiate Contact class
digester.addObjectCreate("configuration/database",
Database.class );
// set type property of Contact instance when 'type'
attribute is found
//digester.addSetProperties("configuration/contact",
"type", "type" );
// set different properties of Contact instance using
specified methods
digester.addCallMethod("configuration/database/url",
"setUrl", 0);
digester.addCallMethod("configuration/database/driver",
"setDriver", 0);
digester.addCallMethod("configuration/database/user-name",
"setUserName", 0);
digester.addCallMethod("configuration/database/password",
"setPassword", 0);
// call 'addContact' method when the next
'address-book/contact' pattern is seen
digester.addSetNext("configuration/database", "addDatabase");
digester.addObjectCreate("configuration/table", Table.class );
digester.addSetProperties("configuration/table", "name",
"name");
digester.addCallMethod("configuration/table/backup-file",
"setFile", 0);
digester.addSetNext("configuration/table", "addTable");
// now that rules and actions are configured, start the
parsing process
ConfigParser abp = (ConfigParser)digester.parse(new
File("config-digest.xml"));
ConfigParser configParser = new ConfigParser();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Second one:
public class ConfigParser
{
public ConfigParser() throws IOException, SAXException
{
// instantiate Digester and disable XML validation
Digester digester = new Digester();
digester.setValidating(false);
// instantiate AddressBookParser class
digester.addObjectCreate("configuration", ConfigParser.class);
// instantiate Contact class
digester.addObjectCreate("configuration/database", Database.class );
// set type property of Contact instance when 'type' attribute
is found
//digester.addSetProperties("configuration/contact",
"type", "type" );
// set different properties of Contact instance using specified
methods
digester.addCallMethod("configuration/database/url", "setUrl", 0);
digester.addCallMethod("configuration/database/driver",
"setDriver", 0);
digester.addCallMethod("configuration/database/user-name",
"setUserName", 0);
digester.addCallMethod("configuration/database/password",
"setPassword", 0);
// call 'addContact' method when the next 'address-book/contact'
pattern is seen
digester.addSetNext("configuration/database", "addDatabase");
digester.addObjectCreate("configuration/table", Table.class );
digester.addSetProperties("configuration/table", "name", "name");
digester.addCallMethod("configuration/table/backup-file",
"setFile", 0);
digester.addSetNext("configuration/table", "addTable");
// now that rules and actions are configured, start the parsing
process
ConfigParser abp = (ConfigParser)digester.parse(new
File("config-digest.xml"));
}
/**
* Prints the contact information to standard output.
*
* @param contact the <code>Contact</code> to print out
*/
public void addDatabase(Database database)
{
System.out.println("URL: " + database.getUrl());
System.out.println("Driver: " + database.getDriver());
System.out.println("User Name: " + database.getUserName());
System.out.println("Password: " + database.getPassword());
}
public void addTable(Table table)
{
System.out.println("Name: " + table.getName());
System.out.println("File: " + table.getFile());
}
/**
* Configures Digester rules and actions, parses the XML file specified
* as the first argument.
*
* @param args command line arguments
*/
public static void main(String[] args)
{
try {
ConfigParser configParser = new ConfigParser();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Thanks,
Mike Zatko
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: Digester Question
Posted by Juan Alvarado <ja...@duocash.com>.
Thanks Gary, I will look into it.
On Dec 22, 2003, at 6:25 PM, Gary S. Cuozzo wrote:
> Juan,
> I don't know if it will suit your needs, but I've had good luck with
> betwixt project which I think is based on Digester.
>
> Gary.
>
>
> On Mon, 2003-12-22 at 18:18, Juan Alvarado wrote:
>> Simon thanks for all of your help and comments.
>>
>> Off the top of your head can you tell me what tools you have used if
>> any that will allow me to convert from object to xml.
>>
>> Thanks in advance
>>
>> On Dec 22, 2003, at 6:14 PM, Simon Kitching wrote:
>>
>>> On Tue, 2003-12-23 at 11:45, Juan Alvarado wrote:
>>>> Hello:
>>>>
>>>
>>> Hi Juan,
>>>
>>> In the CVS repository there are now some examples of using Digester
>>> that
>>> will hopefully answer your questions. You can see these examples by
>>> following the instructions for checking out files from CVS, or use
>>> the
>>> CVS web interface to browse/download the files.
>>>
>>> See:
>>> http://cvs.apache.org/viewcvs.cgi/jakarta-commons/digester/src/
>>> examples/
>>>
>>> The page http://jakarta.apache.org/commons/digester/ has a Resources
>>> section that contains links to some published articles about Digester
>>> that may also be useful.
>>>
>>> You should make sure you read the package description for digester.
>>> Follow the instructions in the "Documentation" section of the page
>>> linked above.
>>>
>>>> As you can see, the node <DebitRequests ReportSuccesses="true">
>>>> contains an attribute ReportSuccesses="true". I need to be able to
>>>> grab
>>>> that value so that it can be populated into my corresponding bean.
>>>> Additionally there might be times when there is more than one
>>>> attribute
>>>> in a given node and obviously I would need to get those values also.
>>>> Could someone please tell me if this is possible and if so, how to
>>>> accomplish this.
>>>
>>> It is definitely possible to map xml attributes to properties in your
>>> classes. The examples demonstrate how to do this.
>>>
>>>>
>>>> NEXT QUESTION:
>>>>
>>>> My application not only has to parse this XML stream, but we also
>>>> have
>>>> to create this XML from in certain situations. We might for example
>>>> receive a request through the web with the necessary parameters and
>>>> values needed to construct the XML and then pass on to the next
>>>> layer.
>>>> Can anyone tell me if the digester framework can handle this and if
>>>> so,
>>>> I'd appreciate some sample code.
>>>
>>> If you are asking about converting a set of CGI parameters to XML,
>>> then
>>> no Digester won't help with this.
>>>
>>> If you are asking about converting a tree of java objects into an XML
>>> representation ("serializing to xml") then you should have a look at
>>> "betwixt" which is also a Jakarta Commons project.
>>>
>>> Digester only handles xml->objects, not objects->xml.
>>>
>>>>
>>>> Thanks in advance.
>>>
>>> You're welcome. If you have more questions after reading the docs
>>> feel
>>> free to ask. One minor note: by convention emails in this list should
>>> have the project listed in square brackets, eg
>>> "[digester] how to handle xml attributes?"
>>>
>>> Subscribers to this list often filter emails using this pattern, so
>>> if
>>> you don't use it then your email might not reach the right people...
>>>
>>> Regards,
>>>
>>> Simon
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> --
> Gary S. Cuozzo <ga...@innovationsw.com>
> Innovation Software Group, LLC
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: Digester Question
Posted by "Gary S. Cuozzo" <ga...@innovationsw.com>.
Juan,
I don't know if it will suit your needs, but I've had good luck with
betwixt project which I think is based on Digester.
Gary.
On Mon, 2003-12-22 at 18:18, Juan Alvarado wrote:
> Simon thanks for all of your help and comments.
>
> Off the top of your head can you tell me what tools you have used if
> any that will allow me to convert from object to xml.
>
> Thanks in advance
>
> On Dec 22, 2003, at 6:14 PM, Simon Kitching wrote:
>
> > On Tue, 2003-12-23 at 11:45, Juan Alvarado wrote:
> >> Hello:
> >>
> >
> > Hi Juan,
> >
> > In the CVS repository there are now some examples of using Digester
> > that
> > will hopefully answer your questions. You can see these examples by
> > following the instructions for checking out files from CVS, or use the
> > CVS web interface to browse/download the files.
> >
> > See:
> > http://cvs.apache.org/viewcvs.cgi/jakarta-commons/digester/src/
> > examples/
> >
> > The page http://jakarta.apache.org/commons/digester/ has a Resources
> > section that contains links to some published articles about Digester
> > that may also be useful.
> >
> > You should make sure you read the package description for digester.
> > Follow the instructions in the "Documentation" section of the page
> > linked above.
> >
> >> As you can see, the node <DebitRequests ReportSuccesses="true">
> >> contains an attribute ReportSuccesses="true". I need to be able to
> >> grab
> >> that value so that it can be populated into my corresponding bean.
> >> Additionally there might be times when there is more than one
> >> attribute
> >> in a given node and obviously I would need to get those values also.
> >> Could someone please tell me if this is possible and if so, how to
> >> accomplish this.
> >
> > It is definitely possible to map xml attributes to properties in your
> > classes. The examples demonstrate how to do this.
> >
> >>
> >> NEXT QUESTION:
> >>
> >> My application not only has to parse this XML stream, but we also have
> >> to create this XML from in certain situations. We might for example
> >> receive a request through the web with the necessary parameters and
> >> values needed to construct the XML and then pass on to the next layer.
> >> Can anyone tell me if the digester framework can handle this and if
> >> so,
> >> I'd appreciate some sample code.
> >
> > If you are asking about converting a set of CGI parameters to XML, then
> > no Digester won't help with this.
> >
> > If you are asking about converting a tree of java objects into an XML
> > representation ("serializing to xml") then you should have a look at
> > "betwixt" which is also a Jakarta Commons project.
> >
> > Digester only handles xml->objects, not objects->xml.
> >
> >>
> >> Thanks in advance.
> >
> > You're welcome. If you have more questions after reading the docs feel
> > free to ask. One minor note: by convention emails in this list should
> > have the project listed in square brackets, eg
> > "[digester] how to handle xml attributes?"
> >
> > Subscribers to this list often filter emails using this pattern, so if
> > you don't use it then your email might not reach the right people...
> >
> > Regards,
> >
> > Simon
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
--
Gary S. Cuozzo <ga...@innovationsw.com>
Innovation Software Group, LLC
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: Digester Question
Posted by Juan Alvarado <ja...@duocash.com>.
Simon thanks for all of your help and comments.
Off the top of your head can you tell me what tools you have used if
any that will allow me to convert from object to xml.
Thanks in advance
On Dec 22, 2003, at 6:14 PM, Simon Kitching wrote:
> On Tue, 2003-12-23 at 11:45, Juan Alvarado wrote:
>> Hello:
>>
>
> Hi Juan,
>
> In the CVS repository there are now some examples of using Digester
> that
> will hopefully answer your questions. You can see these examples by
> following the instructions for checking out files from CVS, or use the
> CVS web interface to browse/download the files.
>
> See:
> http://cvs.apache.org/viewcvs.cgi/jakarta-commons/digester/src/
> examples/
>
> The page http://jakarta.apache.org/commons/digester/ has a Resources
> section that contains links to some published articles about Digester
> that may also be useful.
>
> You should make sure you read the package description for digester.
> Follow the instructions in the "Documentation" section of the page
> linked above.
>
>> As you can see, the node <DebitRequests ReportSuccesses="true">
>> contains an attribute ReportSuccesses="true". I need to be able to
>> grab
>> that value so that it can be populated into my corresponding bean.
>> Additionally there might be times when there is more than one
>> attribute
>> in a given node and obviously I would need to get those values also.
>> Could someone please tell me if this is possible and if so, how to
>> accomplish this.
>
> It is definitely possible to map xml attributes to properties in your
> classes. The examples demonstrate how to do this.
>
>>
>> NEXT QUESTION:
>>
>> My application not only has to parse this XML stream, but we also have
>> to create this XML from in certain situations. We might for example
>> receive a request through the web with the necessary parameters and
>> values needed to construct the XML and then pass on to the next layer.
>> Can anyone tell me if the digester framework can handle this and if
>> so,
>> I'd appreciate some sample code.
>
> If you are asking about converting a set of CGI parameters to XML, then
> no Digester won't help with this.
>
> If you are asking about converting a tree of java objects into an XML
> representation ("serializing to xml") then you should have a look at
> "betwixt" which is also a Jakarta Commons project.
>
> Digester only handles xml->objects, not objects->xml.
>
>>
>> Thanks in advance.
>
> You're welcome. If you have more questions after reading the docs feel
> free to ask. One minor note: by convention emails in this list should
> have the project listed in square brackets, eg
> "[digester] how to handle xml attributes?"
>
> Subscribers to this list often filter emails using this pattern, so if
> you don't use it then your email might not reach the right people...
>
> Regards,
>
> Simon
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: Digester Question
Posted by Simon Kitching <si...@ecnetwork.co.nz>.
On Tue, 2003-12-23 at 11:45, Juan Alvarado wrote:
> Hello:
>
Hi Juan,
In the CVS repository there are now some examples of using Digester that
will hopefully answer your questions. You can see these examples by
following the instructions for checking out files from CVS, or use the
CVS web interface to browse/download the files.
See:
http://cvs.apache.org/viewcvs.cgi/jakarta-commons/digester/src/examples/
The page http://jakarta.apache.org/commons/digester/ has a Resources
section that contains links to some published articles about Digester
that may also be useful.
You should make sure you read the package description for digester.
Follow the instructions in the "Documentation" section of the page
linked above.
> As you can see, the node <DebitRequests ReportSuccesses="true">
> contains an attribute ReportSuccesses="true". I need to be able to grab
> that value so that it can be populated into my corresponding bean.
> Additionally there might be times when there is more than one attribute
> in a given node and obviously I would need to get those values also.
> Could someone please tell me if this is possible and if so, how to
> accomplish this.
It is definitely possible to map xml attributes to properties in your
classes. The examples demonstrate how to do this.
>
> NEXT QUESTION:
>
> My application not only has to parse this XML stream, but we also have
> to create this XML from in certain situations. We might for example
> receive a request through the web with the necessary parameters and
> values needed to construct the XML and then pass on to the next layer.
> Can anyone tell me if the digester framework can handle this and if so,
> I'd appreciate some sample code.
If you are asking about converting a set of CGI parameters to XML, then
no Digester won't help with this.
If you are asking about converting a tree of java objects into an XML
representation ("serializing to xml") then you should have a look at
"betwixt" which is also a Jakarta Commons project.
Digester only handles xml->objects, not objects->xml.
>
> Thanks in advance.
You're welcome. If you have more questions after reading the docs feel
free to ask. One minor note: by convention emails in this list should
have the project listed in square brackets, eg
"[digester] how to handle xml attributes?"
Subscribers to this list often filter emails using this pattern, so if
you don't use it then your email might not reach the right people...
Regards,
Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: Digester Question
Posted by Juan Alvarado <ja...@duocash.com>.
Ok great.. Keep me posted with that.
Take care
On Dec 23, 2003, at 1:52 PM, Tim O'Brien wrote:
> I do not know of any problem, but then again, I only use Betwixt in a
> very
> straightforward situation.
>
> If you would like to check on the open issues in Bugzilla, here is the
> link:
> http://nagoya.apache.org/bugzilla/buglist.cgi?
> bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&email1=&emailtyp
> e1=substring&emailassigned_to1=1&email2=&emailtype2=substring&emailrepo
> rter2=1&bugidtype=include&bug_id=&changedin=&votes=&chfieldfrom=&chfiel
> dto=Now&chfieldvalue=&product=Commons&component=Betwixt&short_desc=&sho
> rt_desc_type=allwordssubstr&long_desc=&long_desc_type=allwordssubstr&bu
> g_file_loc=&bug_file_loc_type=allwordssubstr&keywords=&keywords_type=an
> ywords&field0-0-0=noop&type0-0-0=noop&value0-0
> -0=&cmdtype=doit&order=%27Importance%27
>
>
> Betwixt is a helpful utility, it has been sitting at an alpha 1.0 stage
> for a bit too long. I'll agitate on the commons-dev list, and roust
> some
> answers out of the group.
>
> Tim
>
>
>
> On Tue, 23 Dec 2003, Juan Alvarado wrote:
>
>> Ok will do.
>>
>> Can you tell me if even though it is in alpha release, if you've
>> encountered or heard of any major problems with it.
>>
>> Thanks
>>
>> On Dec 23, 2003, at 12:46 PM, Tim O'Brien wrote:
>>
>>> I left out more detail, especially concerning the situation where the
>>> Play
>>> bean contains a property that happens to be a Character bean.
>>>
>>> Please also see the very well written online docs with Betwixt:
>>> http://jakarta.apache.org/commons/betwixt/guide/binding.html
>>>
>>> If you notice any glaring omissions please feel free to this
>>> community
>>> know.
>>>
>>> Tim
>>>
>>> On Tue, 23 Dec 2003, Juan Alvarado wrote:
>>>
>>>> Tim:
>>>>
>>>> Thanks for the help and the sample code. I really appreciate it.
>>>> This
>>>> will help us get up and running really fast.
>>>>
>>>> Take care,
>>>>
>>>> On Dec 22, 2003, at 8:23 PM, Tim O'Brien wrote:
>>>>
>>>>> Juan, the Digester is pretty straightforward, I'd recommend using
>>>>> the
>>>>> XML rules sets.
>>>>>
>>>>> As far as Object -> XML, try using Betwixt. It is very
>>>>> straightfoward.
>>>>>
>>>>> Assume you have a Play JavaBean with a genre, year, language, and
>>>>> author properties.
>>>>>
>>>>> Create a file named "Play.betwixt", and make sure that it resides
>>>>> in
>>>>> the classpath as a sibling to Play.class.
>>>>>
>>>>> <info primitiveTypes="element">
>>>>> <element name="play">
>>>>> <attribute name="genre" property="genre"/>
>>>>> <attribute name="year" property="year"/>
>>>>> <attribute name="language" property="language"/>
>>>>> <addDefaults/>
>>>>> </element>
>>>>> </info>
>>>>>
>>>>> *** Then you can use the code below to write out an XML file.
>>>>>
>>>>> Play play = new Play();
>>>>> play.setGenre( "blah" );
>>>>> play.setYear( 1232 );
>>>>> play.setLanguage( "Danish" );
>>>>> play.setAuthor( "Ali G.");
>>>>>
>>>>> BeanWriter beanWriter = new BeanWriter();
>>>>> beanWriter.enablePrettyPrint();
>>>>> beanWriter.write(play);
>>>>> System.out.println(beanWriter.toString());
>>>>>
>>>>> *** This will spit out something like this:
>>>>>
>>>>> <play genre="blah" year="1232" language="Danish">
>>>>> <author>Ali G.</author>
>>>>> </play>
>>>>>
>>>>> So, in other words, using Betwixt is as easy as creating a series
>>>>> of
>>>>> .betwixt files that you place in the Classpath.
>>>>>
>>>>> Good Luck.
>>>>>
>>>>>
>>>>> Juan Alvarado wrote:
>>>>>
>>>>>> Hello:
>>>>>>
>>>>>> I am relatively new to xml parsing and I just started using the
>>>>>> commons-digester tools and it seems like it might fit my needs.
>>>>>>
>>>>>> First let me apologize to all you seasoned pros in the field of
>>>>>> XML
>>>>>> in the event that my question seems too simple or if I am just not
>>>>>> using the right terminology.
>>>>>>
>>>>>> My question is as follows.
>>>>>>
>>>>>> The particular XML that I am working with and in need to parse is
>>>>>> composed as follows:
>>>>>>
>>>>>> <?xml version="1.0"?>
>>>>>> <IDTDebitInterface>
>>>>>> <UserInfo>
>>>>>> <username>Juan</username>
>>>>>> <password>Alvarado</password>
>>>>>> </UserInfo>
>>>>>> <DebitRequests ReportSuccesses="true">
>>>>>> <DebitRequest id="1" type="misctrans">
>>>>>> <account>123</account>
>>>>>> <amount>10</amount>
>>>>>> <transtype>vendordebit</transtype>
>>>>>> <note>Test</note>
>>>>>> <balancetozero>n</balancetozero>
>>>>>> </DebitRequest>
>>>>>> </DebitRequests>
>>>>>> </IDTDebitInterface>
>>>>>>
>>>>>> As you can see, the node <DebitRequests ReportSuccesses="true">
>>>>>> contains an attribute ReportSuccesses="true". I need to be able to
>>>>>> grab that value so that it can be populated into my corresponding
>>>>>> bean. Additionally there might be times when there is more than
>>>>>> one
>>>>>> attribute in a given node and obviously I would need to get those
>>>>>> values also. Could someone please tell me if this is possible and
>>>>>> if
>>>>>> so, how to accomplish this.
>>>>>>
>>>>>> NEXT QUESTION:
>>>>>>
>>>>>> My application not only has to parse this XML stream, but we also
>>>>>> have to create this XML from in certain situations. We might for
>>>>>> example receive a request through the web with the necessary
>>>>>> parameters and values needed to construct the XML and then pass on
>>>>>> to
>>>>>> the next layer. Can anyone tell me if the digester framework can
>>>>>> handle this and if so, I'd appreciate some sample code.
>>>>>>
>>>>>> Thanks in advance.
>>>>>>
>>>>>>
>>>>>> ------------------------------------------------------------------
>>>>>> --
>>>>>> -
>>>>>> To unsubscribe, e-mail:
>>>>>> commons-user-unsubscribe@jakarta.apache.org
>>>>>> For additional commands, e-mail:
>>>>>> commons-user-help@jakarta.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> -------------------------------------------------------------------
>>>>> --
>>>>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>>>> For additional commands, e-mail:
>>>>> commons-user-help@jakarta.apache.org
>>>>>
>>>>>
>>>>
>>>>
>>>> --------------------------------------------------------------------
>>>> -
>>>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail:
>>>> commons-user-help@jakarta.apache.org
>>>>
>>>>
>>>>
>>>
>>> --
>>> ----------------------
>>> Tim O'Brien
>>> Evanston, IL
>>> (847) 863-7045
>>> tobrien@discursive.com
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
>>
>
> --
> ----------------------
> Tim O'Brien
> Evanston, IL
> (847) 863-7045
> tobrien@discursive.com
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: Digester Question
Posted by Tim O'Brien <to...@discursive.com>.
I do not know of any problem, but then again, I only use Betwixt in a very
straightforward situation.
If you would like to check on the open issues in Bugzilla, here is the
link:
http://nagoya.apache.org/bugzilla/buglist.cgi?bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&email1=&emailtype1=substring&emailassigned_to1=1&email2=&emailtype2=substring&emailreporter2=1&bugidtype=include&bug_id=&changedin=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&product=Commons&component=Betwixt&short_desc=&short_desc_type=allwordssubstr&long_desc=&long_desc_type=allwordssubstr&bug_file_loc=&bug_file_loc_type=allwordssubstr&keywords=&keywords_type=anywords&field0-0-0=noop&type0-0-0=noop&value0-0-0=&cmdtype=doit&order=%27Importance%27
Betwixt is a helpful utility, it has been sitting at an alpha 1.0 stage
for a bit too long. I'll agitate on the commons-dev list, and roust some
answers out of the group.
Tim
On Tue, 23 Dec 2003, Juan Alvarado wrote:
> Ok will do.
>
> Can you tell me if even though it is in alpha release, if you've
> encountered or heard of any major problems with it.
>
> Thanks
>
> On Dec 23, 2003, at 12:46 PM, Tim O'Brien wrote:
>
> > I left out more detail, especially concerning the situation where the
> > Play
> > bean contains a property that happens to be a Character bean.
> >
> > Please also see the very well written online docs with Betwixt:
> > http://jakarta.apache.org/commons/betwixt/guide/binding.html
> >
> > If you notice any glaring omissions please feel free to this community
> > know.
> >
> > Tim
> >
> > On Tue, 23 Dec 2003, Juan Alvarado wrote:
> >
> >> Tim:
> >>
> >> Thanks for the help and the sample code. I really appreciate it. This
> >> will help us get up and running really fast.
> >>
> >> Take care,
> >>
> >> On Dec 22, 2003, at 8:23 PM, Tim O'Brien wrote:
> >>
> >>> Juan, the Digester is pretty straightforward, I'd recommend using the
> >>> XML rules sets.
> >>>
> >>> As far as Object -> XML, try using Betwixt. It is very
> >>> straightfoward.
> >>>
> >>> Assume you have a Play JavaBean with a genre, year, language, and
> >>> author properties.
> >>>
> >>> Create a file named "Play.betwixt", and make sure that it resides in
> >>> the classpath as a sibling to Play.class.
> >>>
> >>> <info primitiveTypes="element">
> >>> <element name="play">
> >>> <attribute name="genre" property="genre"/>
> >>> <attribute name="year" property="year"/>
> >>> <attribute name="language" property="language"/>
> >>> <addDefaults/>
> >>> </element>
> >>> </info>
> >>>
> >>> *** Then you can use the code below to write out an XML file.
> >>>
> >>> Play play = new Play();
> >>> play.setGenre( "blah" );
> >>> play.setYear( 1232 );
> >>> play.setLanguage( "Danish" );
> >>> play.setAuthor( "Ali G.");
> >>>
> >>> BeanWriter beanWriter = new BeanWriter();
> >>> beanWriter.enablePrettyPrint();
> >>> beanWriter.write(play);
> >>> System.out.println(beanWriter.toString());
> >>>
> >>> *** This will spit out something like this:
> >>>
> >>> <play genre="blah" year="1232" language="Danish">
> >>> <author>Ali G.</author>
> >>> </play>
> >>>
> >>> So, in other words, using Betwixt is as easy as creating a series of
> >>> .betwixt files that you place in the Classpath.
> >>>
> >>> Good Luck.
> >>>
> >>>
> >>> Juan Alvarado wrote:
> >>>
> >>>> Hello:
> >>>>
> >>>> I am relatively new to xml parsing and I just started using the
> >>>> commons-digester tools and it seems like it might fit my needs.
> >>>>
> >>>> First let me apologize to all you seasoned pros in the field of XML
> >>>> in the event that my question seems too simple or if I am just not
> >>>> using the right terminology.
> >>>>
> >>>> My question is as follows.
> >>>>
> >>>> The particular XML that I am working with and in need to parse is
> >>>> composed as follows:
> >>>>
> >>>> <?xml version="1.0"?>
> >>>> <IDTDebitInterface>
> >>>> <UserInfo>
> >>>> <username>Juan</username>
> >>>> <password>Alvarado</password>
> >>>> </UserInfo>
> >>>> <DebitRequests ReportSuccesses="true">
> >>>> <DebitRequest id="1" type="misctrans">
> >>>> <account>123</account>
> >>>> <amount>10</amount>
> >>>> <transtype>vendordebit</transtype>
> >>>> <note>Test</note>
> >>>> <balancetozero>n</balancetozero>
> >>>> </DebitRequest>
> >>>> </DebitRequests>
> >>>> </IDTDebitInterface>
> >>>>
> >>>> As you can see, the node <DebitRequests ReportSuccesses="true">
> >>>> contains an attribute ReportSuccesses="true". I need to be able to
> >>>> grab that value so that it can be populated into my corresponding
> >>>> bean. Additionally there might be times when there is more than one
> >>>> attribute in a given node and obviously I would need to get those
> >>>> values also. Could someone please tell me if this is possible and if
> >>>> so, how to accomplish this.
> >>>>
> >>>> NEXT QUESTION:
> >>>>
> >>>> My application not only has to parse this XML stream, but we also
> >>>> have to create this XML from in certain situations. We might for
> >>>> example receive a request through the web with the necessary
> >>>> parameters and values needed to construct the XML and then pass on
> >>>> to
> >>>> the next layer. Can anyone tell me if the digester framework can
> >>>> handle this and if so, I'd appreciate some sample code.
> >>>>
> >>>> Thanks in advance.
> >>>>
> >>>>
> >>>> --------------------------------------------------------------------
> >>>> -
> >>>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> >>>> For additional commands, e-mail:
> >>>> commons-user-help@jakarta.apache.org
> >>>>
> >>>>
> >>>>
> >>>
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> >>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >>>
> >>>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >>
> >>
> >>
> >
> > --
> > ----------------------
> > Tim O'Brien
> > Evanston, IL
> > (847) 863-7045
> > tobrien@discursive.com
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>
--
----------------------
Tim O'Brien
Evanston, IL
(847) 863-7045
tobrien@discursive.com
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: Digester Question
Posted by Juan Alvarado <ja...@duocash.com>.
Ok will do.
Can you tell me if even though it is in alpha release, if you've
encountered or heard of any major problems with it.
Thanks
On Dec 23, 2003, at 12:46 PM, Tim O'Brien wrote:
> I left out more detail, especially concerning the situation where the
> Play
> bean contains a property that happens to be a Character bean.
>
> Please also see the very well written online docs with Betwixt:
> http://jakarta.apache.org/commons/betwixt/guide/binding.html
>
> If you notice any glaring omissions please feel free to this community
> know.
>
> Tim
>
> On Tue, 23 Dec 2003, Juan Alvarado wrote:
>
>> Tim:
>>
>> Thanks for the help and the sample code. I really appreciate it. This
>> will help us get up and running really fast.
>>
>> Take care,
>>
>> On Dec 22, 2003, at 8:23 PM, Tim O'Brien wrote:
>>
>>> Juan, the Digester is pretty straightforward, I'd recommend using the
>>> XML rules sets.
>>>
>>> As far as Object -> XML, try using Betwixt. It is very
>>> straightfoward.
>>>
>>> Assume you have a Play JavaBean with a genre, year, language, and
>>> author properties.
>>>
>>> Create a file named "Play.betwixt", and make sure that it resides in
>>> the classpath as a sibling to Play.class.
>>>
>>> <info primitiveTypes="element">
>>> <element name="play">
>>> <attribute name="genre" property="genre"/>
>>> <attribute name="year" property="year"/>
>>> <attribute name="language" property="language"/>
>>> <addDefaults/>
>>> </element>
>>> </info>
>>>
>>> *** Then you can use the code below to write out an XML file.
>>>
>>> Play play = new Play();
>>> play.setGenre( "blah" );
>>> play.setYear( 1232 );
>>> play.setLanguage( "Danish" );
>>> play.setAuthor( "Ali G.");
>>>
>>> BeanWriter beanWriter = new BeanWriter();
>>> beanWriter.enablePrettyPrint();
>>> beanWriter.write(play);
>>> System.out.println(beanWriter.toString());
>>>
>>> *** This will spit out something like this:
>>>
>>> <play genre="blah" year="1232" language="Danish">
>>> <author>Ali G.</author>
>>> </play>
>>>
>>> So, in other words, using Betwixt is as easy as creating a series of
>>> .betwixt files that you place in the Classpath.
>>>
>>> Good Luck.
>>>
>>>
>>> Juan Alvarado wrote:
>>>
>>>> Hello:
>>>>
>>>> I am relatively new to xml parsing and I just started using the
>>>> commons-digester tools and it seems like it might fit my needs.
>>>>
>>>> First let me apologize to all you seasoned pros in the field of XML
>>>> in the event that my question seems too simple or if I am just not
>>>> using the right terminology.
>>>>
>>>> My question is as follows.
>>>>
>>>> The particular XML that I am working with and in need to parse is
>>>> composed as follows:
>>>>
>>>> <?xml version="1.0"?>
>>>> <IDTDebitInterface>
>>>> <UserInfo>
>>>> <username>Juan</username>
>>>> <password>Alvarado</password>
>>>> </UserInfo>
>>>> <DebitRequests ReportSuccesses="true">
>>>> <DebitRequest id="1" type="misctrans">
>>>> <account>123</account>
>>>> <amount>10</amount>
>>>> <transtype>vendordebit</transtype>
>>>> <note>Test</note>
>>>> <balancetozero>n</balancetozero>
>>>> </DebitRequest>
>>>> </DebitRequests>
>>>> </IDTDebitInterface>
>>>>
>>>> As you can see, the node <DebitRequests ReportSuccesses="true">
>>>> contains an attribute ReportSuccesses="true". I need to be able to
>>>> grab that value so that it can be populated into my corresponding
>>>> bean. Additionally there might be times when there is more than one
>>>> attribute in a given node and obviously I would need to get those
>>>> values also. Could someone please tell me if this is possible and if
>>>> so, how to accomplish this.
>>>>
>>>> NEXT QUESTION:
>>>>
>>>> My application not only has to parse this XML stream, but we also
>>>> have to create this XML from in certain situations. We might for
>>>> example receive a request through the web with the necessary
>>>> parameters and values needed to construct the XML and then pass on
>>>> to
>>>> the next layer. Can anyone tell me if the digester framework can
>>>> handle this and if so, I'd appreciate some sample code.
>>>>
>>>> Thanks in advance.
>>>>
>>>>
>>>> --------------------------------------------------------------------
>>>> -
>>>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail:
>>>> commons-user-help@jakarta.apache.org
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
>>
>
> --
> ----------------------
> Tim O'Brien
> Evanston, IL
> (847) 863-7045
> tobrien@discursive.com
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: Digester Question
Posted by Tim O'Brien <to...@discursive.com>.
I left out more detail, especially concerning the situation where the Play
bean contains a property that happens to be a Character bean.
Please also see the very well written online docs with Betwixt:
http://jakarta.apache.org/commons/betwixt/guide/binding.html
If you notice any glaring omissions please feel free to this community
know.
Tim
On Tue, 23 Dec 2003, Juan Alvarado wrote:
> Tim:
>
> Thanks for the help and the sample code. I really appreciate it. This
> will help us get up and running really fast.
>
> Take care,
>
> On Dec 22, 2003, at 8:23 PM, Tim O'Brien wrote:
>
> > Juan, the Digester is pretty straightforward, I'd recommend using the
> > XML rules sets.
> >
> > As far as Object -> XML, try using Betwixt. It is very straightfoward.
> >
> > Assume you have a Play JavaBean with a genre, year, language, and
> > author properties.
> >
> > Create a file named "Play.betwixt", and make sure that it resides in
> > the classpath as a sibling to Play.class.
> >
> > <info primitiveTypes="element">
> > <element name="play">
> > <attribute name="genre" property="genre"/>
> > <attribute name="year" property="year"/>
> > <attribute name="language" property="language"/>
> > <addDefaults/>
> > </element>
> > </info>
> >
> > *** Then you can use the code below to write out an XML file.
> >
> > Play play = new Play();
> > play.setGenre( "blah" );
> > play.setYear( 1232 );
> > play.setLanguage( "Danish" );
> > play.setAuthor( "Ali G.");
> >
> > BeanWriter beanWriter = new BeanWriter();
> > beanWriter.enablePrettyPrint();
> > beanWriter.write(play);
> > System.out.println(beanWriter.toString());
> >
> > *** This will spit out something like this:
> >
> > <play genre="blah" year="1232" language="Danish">
> > <author>Ali G.</author>
> > </play>
> >
> > So, in other words, using Betwixt is as easy as creating a series of
> > .betwixt files that you place in the Classpath.
> >
> > Good Luck.
> >
> >
> > Juan Alvarado wrote:
> >
> >> Hello:
> >>
> >> I am relatively new to xml parsing and I just started using the
> >> commons-digester tools and it seems like it might fit my needs.
> >>
> >> First let me apologize to all you seasoned pros in the field of XML
> >> in the event that my question seems too simple or if I am just not
> >> using the right terminology.
> >>
> >> My question is as follows.
> >>
> >> The particular XML that I am working with and in need to parse is
> >> composed as follows:
> >>
> >> <?xml version="1.0"?>
> >> <IDTDebitInterface>
> >> <UserInfo>
> >> <username>Juan</username>
> >> <password>Alvarado</password>
> >> </UserInfo>
> >> <DebitRequests ReportSuccesses="true">
> >> <DebitRequest id="1" type="misctrans">
> >> <account>123</account>
> >> <amount>10</amount>
> >> <transtype>vendordebit</transtype>
> >> <note>Test</note>
> >> <balancetozero>n</balancetozero>
> >> </DebitRequest>
> >> </DebitRequests>
> >> </IDTDebitInterface>
> >>
> >> As you can see, the node <DebitRequests ReportSuccesses="true">
> >> contains an attribute ReportSuccesses="true". I need to be able to
> >> grab that value so that it can be populated into my corresponding
> >> bean. Additionally there might be times when there is more than one
> >> attribute in a given node and obviously I would need to get those
> >> values also. Could someone please tell me if this is possible and if
> >> so, how to accomplish this.
> >>
> >> NEXT QUESTION:
> >>
> >> My application not only has to parse this XML stream, but we also
> >> have to create this XML from in certain situations. We might for
> >> example receive a request through the web with the necessary
> >> parameters and values needed to construct the XML and then pass on to
> >> the next layer. Can anyone tell me if the digester framework can
> >> handle this and if so, I'd appreciate some sample code.
> >>
> >> Thanks in advance.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >>
> >>
> >>
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>
--
----------------------
Tim O'Brien
Evanston, IL
(847) 863-7045
tobrien@discursive.com
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: Digester Question
Posted by Juan Alvarado <ja...@duocash.com>.
Tim:
Thanks for the help and the sample code. I really appreciate it. This
will help us get up and running really fast.
Take care,
On Dec 22, 2003, at 8:23 PM, Tim O'Brien wrote:
> Juan, the Digester is pretty straightforward, I'd recommend using the
> XML rules sets.
>
> As far as Object -> XML, try using Betwixt. It is very straightfoward.
>
> Assume you have a Play JavaBean with a genre, year, language, and
> author properties.
>
> Create a file named "Play.betwixt", and make sure that it resides in
> the classpath as a sibling to Play.class.
>
> <info primitiveTypes="element">
> <element name="play">
> <attribute name="genre" property="genre"/>
> <attribute name="year" property="year"/>
> <attribute name="language" property="language"/>
> <addDefaults/>
> </element>
> </info>
>
> *** Then you can use the code below to write out an XML file.
>
> Play play = new Play();
> play.setGenre( "blah" );
> play.setYear( 1232 );
> play.setLanguage( "Danish" );
> play.setAuthor( "Ali G.");
>
> BeanWriter beanWriter = new BeanWriter();
> beanWriter.enablePrettyPrint();
> beanWriter.write(play);
> System.out.println(beanWriter.toString());
>
> *** This will spit out something like this:
>
> <play genre="blah" year="1232" language="Danish">
> <author>Ali G.</author>
> </play>
>
> So, in other words, using Betwixt is as easy as creating a series of
> .betwixt files that you place in the Classpath.
>
> Good Luck.
>
>
> Juan Alvarado wrote:
>
>> Hello:
>>
>> I am relatively new to xml parsing and I just started using the
>> commons-digester tools and it seems like it might fit my needs.
>>
>> First let me apologize to all you seasoned pros in the field of XML
>> in the event that my question seems too simple or if I am just not
>> using the right terminology.
>>
>> My question is as follows.
>>
>> The particular XML that I am working with and in need to parse is
>> composed as follows:
>>
>> <?xml version="1.0"?>
>> <IDTDebitInterface>
>> <UserInfo>
>> <username>Juan</username>
>> <password>Alvarado</password>
>> </UserInfo>
>> <DebitRequests ReportSuccesses="true">
>> <DebitRequest id="1" type="misctrans">
>> <account>123</account>
>> <amount>10</amount>
>> <transtype>vendordebit</transtype>
>> <note>Test</note>
>> <balancetozero>n</balancetozero>
>> </DebitRequest>
>> </DebitRequests>
>> </IDTDebitInterface>
>>
>> As you can see, the node <DebitRequests ReportSuccesses="true">
>> contains an attribute ReportSuccesses="true". I need to be able to
>> grab that value so that it can be populated into my corresponding
>> bean. Additionally there might be times when there is more than one
>> attribute in a given node and obviously I would need to get those
>> values also. Could someone please tell me if this is possible and if
>> so, how to accomplish this.
>>
>> NEXT QUESTION:
>>
>> My application not only has to parse this XML stream, but we also
>> have to create this XML from in certain situations. We might for
>> example receive a request through the web with the necessary
>> parameters and values needed to construct the XML and then pass on to
>> the next layer. Can anyone tell me if the digester framework can
>> handle this and if so, I'd appreciate some sample code.
>>
>> Thanks in advance.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: Digester Question
Posted by Tim O'Brien <to...@discursive.com>.
Juan, the Digester is pretty straightforward, I'd recommend using the
XML rules sets.
As far as Object -> XML, try using Betwixt. It is very straightfoward.
Assume you have a Play JavaBean with a genre, year, language, and author
properties.
Create a file named "Play.betwixt", and make sure that it resides in the
classpath as a sibling to Play.class.
<info primitiveTypes="element">
<element name="play">
<attribute name="genre" property="genre"/>
<attribute name="year" property="year"/>
<attribute name="language" property="language"/>
<addDefaults/>
</element>
</info>
*** Then you can use the code below to write out an XML file.
Play play = new Play();
play.setGenre( "blah" );
play.setYear( 1232 );
play.setLanguage( "Danish" );
play.setAuthor( "Ali G.");
BeanWriter beanWriter = new BeanWriter();
beanWriter.enablePrettyPrint();
beanWriter.write(play);
System.out.println(beanWriter.toString());
*** This will spit out something like this:
<play genre="blah" year="1232" language="Danish">
<author>Ali G.</author>
</play>
So, in other words, using Betwixt is as easy as creating a series of
.betwixt files that you place in the Classpath.
Good Luck.
Juan Alvarado wrote:
> Hello:
>
> I am relatively new to xml parsing and I just started using the
> commons-digester tools and it seems like it might fit my needs.
>
> First let me apologize to all you seasoned pros in the field of XML in
> the event that my question seems too simple or if I am just not using
> the right terminology.
>
> My question is as follows.
>
> The particular XML that I am working with and in need to parse is
> composed as follows:
>
> <?xml version="1.0"?>
> <IDTDebitInterface>
> <UserInfo>
> <username>Juan</username>
> <password>Alvarado</password>
> </UserInfo>
> <DebitRequests ReportSuccesses="true">
> <DebitRequest id="1" type="misctrans">
> <account>123</account>
> <amount>10</amount>
> <transtype>vendordebit</transtype>
> <note>Test</note>
> <balancetozero>n</balancetozero>
> </DebitRequest>
> </DebitRequests>
> </IDTDebitInterface>
>
> As you can see, the node <DebitRequests ReportSuccesses="true">
> contains an attribute ReportSuccesses="true". I need to be able to
> grab that value so that it can be populated into my corresponding
> bean. Additionally there might be times when there is more than one
> attribute in a given node and obviously I would need to get those
> values also. Could someone please tell me if this is possible and if
> so, how to accomplish this.
>
> NEXT QUESTION:
>
> My application not only has to parse this XML stream, but we also have
> to create this XML from in certain situations. We might for example
> receive a request through the web with the necessary parameters and
> values needed to construct the XML and then pass on to the next layer.
> Can anyone tell me if the digester framework can handle this and if
> so, I'd appreciate some sample code.
>
> Thanks in advance.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
RE: Digester Question
Posted by Ivan Rekovic <ri...@verat.net>.
The simplest way of grabing ReportSuccesses is to use SetPropertyRule.
See documentation in digester distribution for this.
Basically you will have to create digester, attach rule (with alias
since ReportSuccesses is not valid bean name), add pattern (something
like IDTDebitInterface/DebitRequests in your case) and parse file with
digester parse method. When parsing is finished you will have property
of your bean setted.
As for your second question. No. Digester can not create XML documents,
but you can look for DOM4J for example witch will suite your needs.
> -----Original Message-----
> From: Juan Alvarado [mailto:jalvarado@duocash.com]
> Sent: Monday, December 22, 2003 11:46 PM
> To: commons-user@jakarta.apache.org
> Subject: Digester Question
>
> Hello:
>
> I am relatively new to xml parsing and I just started using the
> commons-digester tools and it seems like it might fit my needs.
>
> First let me apologize to all you seasoned pros in the field of XML in
> the event that my question seems too simple or if I am just not using
> the right terminology.
>
> My question is as follows.
>
> The particular XML that I am working with and in need to parse is
> composed as follows:
>
> <?xml version="1.0"?>
> <IDTDebitInterface>
> <UserInfo>
> <username>Juan</username>
> <password>Alvarado</password>
> </UserInfo>
> <DebitRequests ReportSuccesses="true">
> <DebitRequest id="1" type="misctrans">
> <account>123</account>
> <amount>10</amount>
> <transtype>vendordebit</transtype>
> <note>Test</note>
> <balancetozero>n</balancetozero>
> </DebitRequest>
> </DebitRequests>
> </IDTDebitInterface>
>
> As you can see, the node <DebitRequests ReportSuccesses="true">
> contains an attribute ReportSuccesses="true". I need to be able to
grab
> that value so that it can be populated into my corresponding bean.
> Additionally there might be times when there is more than one
attribute
> in a given node and obviously I would need to get those values also.
> Could someone please tell me if this is possible and if so, how to
> accomplish this.
>
> NEXT QUESTION:
>
> My application not only has to parse this XML stream, but we also have
> to create this XML from in certain situations. We might for example
> receive a request through the web with the necessary parameters and
> values needed to construct the XML and then pass on to the next layer.
> Can anyone tell me if the digester framework can handle this and if
so,
> I'd appreciate some sample code.
>
> Thanks in advance.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org