473,383 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

XMLTextWriter and decoding special characters.

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
5 9119
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: steve | last post by:
Hi, I am opening a stream that is UTF encoded. I use fgetc to read the stream- which is binary safe. I add every character read to a string. But when I look at the stream, I see some...
1
by: Matthias Stern | last post by:
Hello! I've got a Javascript-PHP encoding problem. (1) Here is the short version: ============================== I'm sending a form textfield via Javascript(!) as URL parameter (GET)...
18
by: LarsM | last post by:
Hi all, I am new to XML, but I use it for an RSS feed. I have one problem, which I have really been struggling with. My XML document is generated from the contents of a MySQL database. It is...
40
by: Peter Row | last post by:
Hi all, Here is my problem: I have a SQL Server 2000 DB with various NVarChar, NText fields in its tables. For some stupid reason the data was inserted into these fields in UTF8 encoding. ...
5
by: reddy | last post by:
I am trying to insert a node into an XMLFile. using XMLTextwriter. My Question is Is it possible to do without using XMLDocument. Because its loading all the the file into memory. I just want to...
4
by: H Lee | last post by:
Hi, I'm an XML newbie, and not sure if this is the appropriate newsgroup to post my question, so feel free to suggest other newgroups where I should post this message if this is the case. I'm...
1
by: rmgalante | last post by:
I have a Windows Service that reads and writes an XML file to disk periodically. I use the XmlSerializer to serialize and deserialize the XML file on disk. I am writing the file using an...
6
by: kath | last post by:
Hi all, Platform: winxp Version: Python 2.3 I have a task of reading files in a folder and creating an one excel file with sheets, one sheet per file, with sheet named...
6
by: clintonG | last post by:
Can anybody make sense of this crazy and inconsistent results? // IE7 Feed Reading View disabled displays this raw XML <?xml version="1.0" encoding="utf-8" ?> <!-- AT&T HTML entities & XML...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.