By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,572 Members | 959 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,572 IT Pros & Developers. It's quick & easy.

XMLTextWriter and decoding special characters.

P: n/a
Hello Everyone,
I have written a simple app. that converts the dataset into
excelspreadsheet.
The App. uses the following architecture.
First it generates the dataset with corresponding datatables(each
datatable represents a worksheet).It uses an Xslt file to do the
transformation of the xml (generate from dataset) and write the
output xml into a xmltextwriter.

The App converts the data into excel with almost all of the formatting
as desired with exception of few.

"In order to display a STRING VALUE into MULTIPLE ROWS WITH IN A CELL
Excel uses a value "
I am aware that xmlTextWriter does not support <xsl:output> not it
support <xsl: disable-output-formatting> tags and also that
xmltextwriter converts invalid characters(&) to a valid xml
characters(&amp;) .

I am using UTF-8 encoding specified in the xmltextwriter.

This inbuilt behaviour is causing a formatting issue. As the
resulting xml has this character escaped(&amp;#10;) which is differnt
from ( ), the desired functionality is not achevied.

Any work around is greatly appriciated.

Regards,
Pranay Jain.
Nov 12 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hello Everyone,
I got a work around of this problem. Instead of using a XmlTextWriter
, i tried using a StreamWriter(implementaion of a TextWriter).
The StreamWriter allows the use of <disable-output-escaping> and
thereby retaining the value  

Now my Question is since i am handling huge amount of xml,
probably 50Mb-100Mb which writer is a better option and why?.

Abstracts from MSDN about both:-
The reason going to XMLTextwriter was that its was a forward-only way
of generating streams or files containing XML data and static (Shared
in Visual Basic) members are Mutlithreadsafe.

Regarding StreamWriter :
StreamWriter is designed for character output in a particular
Encoding, whereas classes derived from Stream are designed for byte
input and output.

Any public static (Shared in Visual Basic) members of this type are
safe for multithreaded operations

BUT By default, a StreamWriter is not thread safe.
Which one do you all recommend to use and if possible please write a
couple of lines why?.

Any insight will be of a great help. Thanks

Regards,
Pranay Jain.
pr*************@hotmail.com (Jain, Pranay Kumar) wrote in message news:<26**************************@posting.google. com>...
Hello Everyone,
I have written a simple app. that converts the dataset into
excelspreadsheet.
The App. uses the following architecture.
First it generates the dataset with corresponding datatables(each
datatable represents a worksheet).It uses an Xslt file to do the
transformation of the xml (generate from dataset) and write the
output xml into a xmltextwriter.

The App converts the data into excel with almost all of the formatting
as desired with exception of few.

"In order to display a STRING VALUE into MULTIPLE ROWS WITH IN A CELL
Excel uses a value "
I am aware that xmlTextWriter does not support <xsl:output> not it
support <xsl: disable-output-escaping> tags and also that
xmltextwriter converts invalid characters(&) to a valid xml
characters(&amp;) .

I am using UTF-8 encoding specified in the xmltextwriter.

This inbuilt behaviour is causing a formatting issue. As the
resulting xml has this character escaped(&amp;#10;) which is differnt
from ( ), the desired functionality is not achevied.

Any work around is greatly appriciated.

Regards,
Pranay Jain.

Nov 12 '05 #2

P: n/a
Jain, Pranay Kumar wrote:
Now my Question is since i am handling huge amount of xml,
probably 50Mb-100Mb which writer is a better option and why?.


I don't think there is any significant difference here, but using
TextWriter or even Stream is going to be slightly faster as it
eliminates one chain (XmlWriter) in the transformation pipeline. It
would be interesting to measure some real XML document transformations
though.
--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 12 '05 #3

P: n/a
Thanks Oleg,
Now when you say stream i am sure you mean MemoryStream and not
streamwriter as textwriter will include streamwriter.

Correct me if i am wrong, the transformed xml will be stored as an
xmldocument in the stream and to my best understanding the xmldocument
utilizes more memory then xpathdocuments and few more..
With MemoryStream i feel that it will cause a real performance issue
as we are trying to Transform huge amount of data on fly and you know
that .net handles Memory in two different buckets sizes and it may
force the aspnet_wp to recycle if it could not handle it.

That leaves the option of going to streamwriter which basically is a
implementaion of text writer hence my <xsl:> tags will not be ignored.
Do you think a streamwriter will cauase any issue with invalid
characters as it will not convert them to valid characters. Do i need
to make any special changes or setting with streamwriter so that it
just doesnot blow away any invalid characters that can come across?..

Any suggestion...
Again, Thanks for your reply.
Regards,
Pranay Jain
"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message news:<uB**************@TK2MSFTNGP12.phx.gbl>...
Jain, Pranay Kumar wrote:
Now my Question is since i am handling huge amount of xml,
probably 50Mb-100Mb which writer is a better option and why?.


I don't think there is any significant difference here, but using
TextWriter or even Stream is going to be slightly faster as it
eliminates one chain (XmlWriter) in the transformation pipeline. It
would be interesting to measure some real XML document transformations
though.

Nov 12 '05 #4

P: n/a
Jain, Pranay Kumar wrote:
Correct me if i am wrong, the transformed xml will be stored as an
xmldocument in the stream and to my best understanding the xmldocument
utilizes more memory then xpathdocuments and few more.. The result of the transformation is just XML text (bytes) if you
transform to TextWriter or Stream. In XmlWriter case the result is
stream of XmlWriter.WriteXXX() methods.
With MemoryStream i feel that it will cause a real performance issue
as we are trying to Transform huge amount of data on fly Real issue here is not output, but input (use XPathDocument) and XSLT
stylesheet itself (optimize it).
That leaves the option of going to streamwriter which basically is a
implementaion of text writer hence my <xsl:> tags will not be ignored.
Do you think a streamwriter will cauase any issue with invalid
characters as it will not convert them to valid characters.

Never. When transforming to TextWriter, xsl:output encoding attribute is
ignored and output is done in the TextWriter's encoding.
But wait, what do you mean saying "invalid character"?
--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 12 '05 #5

P: n/a
Thanks Oleg,
I agree with your reply. I was thinking wrong w.r.t the memorystream
and the output format. Also w.r.t invalid characters i was referring
to &,<,>,',".
But i realised that the streamwriter writes with character encoding so
it should not be an issue. correct me if i am wrong here.

I have modified my code and now i am using a textwriter to output the
data.
My application works good now. Although , i run to a very basic issue.
How will you calculate the width of a string for excel column. There
is a tag
<ss:column> in which i can specify a fixed width. But i dont wanna
give a static value and i want to calculate the string width value.
Any suggestions??
Regards & Thanks
Pranay Jain.
"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message news:<On*************@TK2MSFTNGP11.phx.gbl>...
Jain, Pranay Kumar wrote:
Correct me if i am wrong, the transformed xml will be stored as an
xmldocument in the stream and to my best understanding the xmldocument
utilizes more memory then xpathdocuments and few more..

The result of the transformation is just XML text (bytes) if you
transform to TextWriter or Stream. In XmlWriter case the result is
stream of XmlWriter.WriteXXX() methods.
With MemoryStream i feel that it will cause a real performance issue
as we are trying to Transform huge amount of data on fly

Real issue here is not output, but input (use XPathDocument) and XSLT
stylesheet itself (optimize it).
That leaves the option of going to streamwriter which basically is a
implementaion of text writer hence my <xsl:> tags will not be ignored.
Do you think a streamwriter will cauase any issue with invalid
characters as it will not convert them to valid characters.

Never. When transforming to TextWriter, xsl:output encoding attribute is
ignored and output is done in the TextWriter's encoding.
But wait, what do you mean saying "invalid character"?

Nov 12 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.