Connecting Tech Pros Worldwide Help | Site Map

Writing XML Table in a text file

  #1  
Old June 25th, 2009, 05:44 PM
Newbie
 
Join Date: May 2009
Posts: 5
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, 33 views)

Last edited by Dormilich; June 26th, 2009 at 01:28 PM. Reason: added [code] tags
  #2  
Old June 28th, 2009, 03:05 PM
Moderator
 
Join Date: Dec 2006
Location: Europe
Posts: 290

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?
  #3  
Old July 7th, 2009, 04:53 PM
Moderator
 
Join Date: Mar 2006
Posts: 1,103

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading and Writing XML from a Dataset with Binary Data Simon answers 4 November 22nd, 2005 10:37 PM
Reading and Writing XML from a Dataset with Binary Data Simon answers 4 November 21st, 2005 09:06 PM
Reading and Writing XML from a Dataset with Binary Data Simon answers 4 November 12th, 2005 04:49 AM
Reading and Writing XML from a Dataset with Binary Data Simon answers 4 August 15th, 2005 12:35 PM