Forum: XML Manager, Topic: XML->CSV conversion issue http://www.ricebridge.com/feeds/forums/xmlman/8.rss Copyright (c) 2004 Ricebridge Topic Posts Wed Aug 09 10:36:03 UTC 2006 Richard Rodger: Hi Ben, To handle t http://local.ricebridge.com/forum/topic.htm?f=xmlman&t=8&s=all#post22 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. Wed, 09 Aug 2006 10:36:03 UTC Ben: Well, I'm not proud of http://local.ricebridge.com/forum/topic.htm?f=xmlman&t=8&s=all#post21 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. Tue, 01 Aug 2006 01:48:30 UTC Ben: Hi, I am running into http://local.ricebridge.com/forum/topic.htm?f=xmlman&t=8&s=all#post20 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! Mon, 31 Jul 2006 23:52:50 UTC