XML Problem writing \r\n

  • Thread starter Thread starter Tomas Vera
  • Start date Start date
T

Tomas Vera

Hello All,
I'm having trouble writing some special characters to an XML file.

I need to output a XMLSS formatted file to be read by Excel.

In some cells there will be some text that contains CR-LF pairs such
as
"this is a long entry\r\nThis is the secondline".

I'm building an XML document to represent my Excel data. This is
working fine.
Then I'm calling xmlDoc.Save(xmlTextWriter)
to create the output.

The problem is that the \r\n are not denoted in any special manner in
the XML file. So Excel does not recogize the line breaks in the cell.

After some toying with the data, I find that this output would work
best:
<Cell>
<Data ss:Type="String">
This is a long entry
This is the secondline
</Data>
</Cell>

However I don't seem to be able to generate the '
' in the XML
output.

What Value/InnerText do I set on my Text node so that the '
' gets
send to the output XML file?

Any help is appreciated.

-tomas
 
For the Benefit of the search engines....
I modified the function that creates the <Cell></Cell> tags to perform
a couple of additional tests to determine whether a "\r\n" exists in
the data object being written out.
If the (string) object contains a "\r\n", then I create a CDATA node,
otherwise I create a Text node to output the data.

The CDATA node preserves the newlines and is input as a literal by
Excel, so the data is represented as expected.

-tomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top