Ricebridge
Search This Site
Dec 01 2008 21:04 UTC

Got a question for us?
Just Ask!


$15 Gift Certificate for every bug you find.

  • Visa MasterCard
  • Visa Delta Laser
  • WorldPay

Bookmark Forum Topic for Ricebridge Java CSV Components at del.icio.us Digg Forum Topic for Ricebridge Java CSV Components at Digg.com Bookmark Forum Topic for Ricebridge Java CSV Components at reddit.com Bookmark Forum Topic for Ricebridge Java CSV Components at YahooMyWeb Bookmark Forum Topic for Ricebridge Java CSV Components at Spurl.net Bookmark Forum Topic for Ricebridge Java CSV Components at Simpy.com Bookmark Polyphasic Mutants at NewsVine Blink this Forum Topic for Ricebridge Java CSV Components at blinklist.com Bookmark Forum Topic for Ricebridge Java CSV Components at Furl.net Fark Forum Topic for Ricebridge Java CSV Components at Fark.com

Topic: XML->CSV conversion issue

Back to Topics Posts RSS Feed
 
Hi,
I am running into a problem where we need to define our CSV to support N (currently N=20) element sets repititions while the XML may have M defined, and set N to a value greater than we see in the real world. The CSV should simply be blank for those sets that are not defined in the XML.

For example, a user profile might contain a set of credit cards, with the XML of multiple profiles looking something like:
<customerSet>
<user>
<userInfo> e.g. name, birthday, email </userInfo>
<chargeCardSet>
<chargeCard> ... </chargeCard>
<chargeCard> ... </chargeCard>
<chargeCard> ... </chargeCard>
</chargeCardSet>
<user>
...
</customerSet>

We'd like to then make a CSV like:
firstName,lastName,...,chargeCard.cardType_1,chargeCard.number_1,...,chargeCard.cardType_20,chargeCard.number_20,...

In XSLT I am able to simply define a chargeCardSet template, count the number of chargeCard nodes, transform them, and then create N - count() empty CSV columns. With XmlManager, I am getting the same chargeCard outputted for every iteration. I have not been able to figure out how to fail to find further elements and output an empty column.

I'm basing my code off of the file-based conversion code in your article.

Any help would be greatly appreciated. Thanks!
Ben Jul 31 2006 23:52
Well, I'm not proud of my work-around. I'm sure that if I new the library better that then I'd know what to extend and add the desired behavior. In the mean time, since I know the data positions in the XML data String array, I know what should be there. So if the data set is a duplicate of the last one, I simply clear out all of the proceeding ones. Then I pass it into CSV manager, and it is converted correctly.

Now my only issue is that XML Manager only outputs the first set, rather then performing a for-each on the template. I'm sure that's easy to fix.
Ben Aug 01 2006 01:48
Hi Ben,

To handle the charge card sets, you will need to use multiple RecordSpecs. An example is shown in the API documentation for RecordSpec: http://www.ricebridge.com/products/xmlman/api/com/ricebridge/xmlman/RecordSpec.html

Basically, you get back a String[] array for each RecordSpec. You need to match up the multiple RecordSpec to create each row of the CSV file.

For each individual record element you will need a RecordSpec. So you will need one for customerSet/user and one for customerSet/user/chargeCardSet/chargeCard

The data for each record is returned as soon as the end element tag is reached. What this means is that for each user, you can store the list of chargeCards seen so far, and when you finally get a user record, you just append them to the CSV fields.

To make this type of processing easier, I generally user a code value as the first field, for example 'card' and 'user'. You can then use this to tell which is which. The Java Bean example does something similar: http://www.ricebridge.com/products/xmlman/examples/beans/README.htm

Finally, the reason that you only see one of the chargeCards in your current code is due to the design of XML Manager. When subelements are repeated, you only see the last one. To handle repeated subelements, you have to use multiple RecordSpecs.
Richard Rodger [Ricebridge Staff] Aug 09 2006 10:36
 
50 Per Page (total: 3)




















comment on this page Home | Search | About Us | Contact Us | Our Products | Documentation | Resources | Login
Copyright © 2004-2008 Ricebridge. All Rights Reserved.