473,322 Members | 1,473 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,322 software developers and data experts.

writing XML from string makes not well formed xml due to too many spaces

Hi,

I've got an asp.net page here that someone else wrote and obviously
expected that it would work because it has been distributed with quite
a large application.

This page allows one to look up some various XML schemas by their
names, not sure where these schemas are actually found at because I
can't seem to find them anywhere other than through this application.

The schemas are encoded as UTF-16, initially the page did not set any
response encoding so it failed because of encoding mismatch. I added
in the ability to set the encoding (and the charset)

Response.ContentEncoding= Encoding.Unicode;
Response.Charset= "UTF-16";

unfortunately the returned XML looks something like this:

< ? x m l v e r s i o n = " 1 . 0 " e n c o d i n g = " u t f - 1
6 " ? >

< x s : s c h e m a e l e m e n t F o r m D e f a u l t = " q u a l
i f i e d " ........

which is obviously an error. I suppose the error is being caused
because the whole thing is being done using stringWriter instead of
one of the XML classes:

System.IO.MemoryStream memStream = new System.IO.MemoryStream();
System.IO.StringWriter sw = new System.IO.StringWriter();

xmlSchema.Write( sw );
returnXml = sw.ToString();

returnXml is returned at the end, and I suppose whatever is calling it
needs a string to write.

So what I want to do is to get rid of these spaces, by the way
memStream doesn't seem to be used anywhere that I can see.

Any help?

Cheers,
Bryan Rasmussen

May 3 '07 #1
1 3083
pantagruel wrote:
Response.ContentEncoding= Encoding.Unicode;
Response.Charset= "UTF-16";

unfortunately the returned XML looks something like this:

< ? x m l v e r s i o n = " 1 . 0 " e n c o d i n g = " u t f - 1
6 " ? >

< x s : s c h e m a e l e m e n t F o r m D e f a u l t = " q u a l
i f i e d " ........

which is obviously an error. I suppose the error is being caused
because the whole thing is being done using stringWriter instead of
one of the XML classes:

System.IO.MemoryStream memStream = new System.IO.MemoryStream();
System.IO.StringWriter sw = new System.IO.StringWriter();

xmlSchema.Write( sw );
returnXml = sw.ToString();

returnXml is returned at the end, and I suppose whatever is calling it
needs a string to write.
Can you show is where the returnXml string is used and how it is used?
Simply creating a string with StringWriter.ToString() should not insert
the blanks you show above.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 5 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Kai Jaensch | last post by:
Hello, i am an newbie and i have to to solve this problem as fast as i can. But at this time i don´t have a lot of success. Can anybody help me (and understand my english :-))? I have a...
16
by: Steve | last post by:
Hi Guys, I have a string which contains data elements separated by spaces. I also have a function which returns the number of characters from the beginning of the string for a given number of...
18
by: JKop | last post by:
Can some-one please point me to a nice site that gives an exhaustive list of all the memberfunctions, membervariables, operators, etc. of the std::string class, along with an informative...
51
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct...
2
by: Trint Smith | last post by:
Ok, My program has been formating .txt files for input into sql server and ran into a problem...the .txt is an export from an accounting package and is only supposed to contain comas (,) between...
5
by: feng | last post by:
OK, all I want is writting a string that represents an XML document into a file, say C:\test.xml. This kind of task used to be so easy with vb6. But now, with VB.Net, it seems turned into a big...
3
by: stathisgotsis | last post by:
Hello everyone, Trusting K&R2 i thought until recently that spaces are ignored in scanf's format string. Reading arguments to the contrary confused me a little. So i now ask: Is...
5
by: slinky | last post by:
I'm struggling with what should be a very basic .aspx/XML issue. I have an XML file. I have a textbox for a user to enter data and a button to submit the data. I don't wont the user to see the...
121
by: swengineer001 | last post by:
Just looking for a few eyes on this code other than my own. void TrimCString(char *str) { // Trim whitespace from beginning: size_t i = 0; size_t j; while(isspace(str)) {
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.