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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
