Connecting Tech Pros Worldwide Forums | Help | Site Map

Writing XML Table in a text file

Newbie
 
Join Date: May 2009
Posts: 5
#1: Jun 25 '09
I have an XML file with a table in the below format,
Expand|Select|Wrap|Line Numbers
  1. <TABLE>
  2.             <TR>
  3.               <TH>EVENT</TH>
  4.               <TH>SUMMARY</TH>
  5.             </TR>
  6.             <TR>
  7.               <TD>US approval of Xience V</TD>
  8.               <TD>Xience V is the first drug-eluting stent to demonstrate superiority over another DES in the primary endpoint of in- segment late loss, in the randomized controlled head-to-head SPIRIT III trial, and received FDA approval in July 2008. Morgan Stanley analysts expect US sales of $700m as early as 2009. Credit Suisse forecast sales of more than $1bn in 2009. Xience V could boost Abbott's annual revenue growth by 1% and EPS growth by 5%.</TD>
  9.             </TR>
  10. </TABLE>
I need to write this XML table in a text file in the below format,
EVENT SUMMARY \
Acquisition of Guidant's Abbott expected to find respite \
vascular business from a volatile pharmaceutical \
market by acquiring Guidant's \
vascular business for $3.8 \
billion in a deal closed in \
April 2006. Morgan Stanley \
analysts suggest the deal will \
secure 10% earnings growth for \
Abbott for the next four years. \

Points to be noted:
Number of characters in a line should not exceed 67.
columns should be equally splitted and the values in the cell should be wrapped to fit into the width of the column.
each line should have "\" at the end.

I have attached the output file with this for your reference.

Please give me some idea on how to do this conversion using C# or XSLT??

your help is much appreciated.
Attached Files
File Type: txt Output File.txt (780 Bytes, 39 views)

Moderator
 
Join Date: Dec 2006
Location: Europe
Posts: 293
#2: Jun 28 '09

re: Writing XML Table in a text file


I don't get it, is that data
Expand|Select|Wrap|Line Numbers
  1. \Acquisition of Guidant's Abbott expected to find respite \
  2. vascular business from a volatile pharmaceutical \
  3. market by acquiring Guidant's \
  4. vascular business for $3.8 \
  5. billion in a deal closed in \
  6. April 2006. Morgan Stanley \
  7. analysts suggest the deal will \
  8. secure 10% earnings growth for \
  9. Abbott for the next four years. \
  10.  
written anywhere in the XML. I can see "EVENT SUMMARY \" in the XML but not the rest of data. Did I miss something?
Moderator
 
Join Date: Mar 2006
Posts: 1,103
#3: Jul 7 '09

re: Writing XML Table in a text file


Would definitely use C#. xslt is not well suited to this task. Assuming you need a space before the \, which limits you to 65 characters total.
http://msdn.microsoft.com/en-us/library/d0z3tk9t.aspx

Something like:
Expand|Select|Wrap|Line Numbers
  1. String td;
  2. String output;
  3. Integer index = 0;
  4. Integer maxChars = 65;
  5. Integer length = td.Length
  6. Integer spaceIndex;
  7.  
  8. foreach td element {// get value of td element into string td. 
  9.  
  10. while (index + maxChars < td.length()){
  11.   spaceIndex = td.LastIndexOf(' ', index, maxChars);
  12.  
  13.   if (spaceIndex == -1) spaceIndex = index + 65; // no spaces in between.
  14.   output += td.substring(index, spaceIndex - index) + " \\";
  15.   index = spaceIndex;
  16. }
  17. if (index != td.length()){
  18.   output += td.substring(index) + " \\";
  19. }
  20. }
  21.  
Reply