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

XML and utf-8

Hi

I have a small and easy program that write a RSS.

Althought the generation works perfect, IE tells me it's not valid.

I get crazy because :
-removing a space at the end of the generated XML seems to help
-It refuses to read more than 5 items in the RSS

there is something i miss there in the XML. It drives me crazy.

Thanks for any help or any link giving help to XML problems

Jonathan

MemoryStream ms = new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(ms,
System.Text.Encoding.UTF8);
writer.Formatting = Formatting.Indented;
WriteRSSPrologue(writer);

SqlConnection Sqlconnection=new SqlConnection ("Data
Source=;Initial Catalog=L;User=;Password=");

SqlCommand cmd=new SqlCommand("select Top 5
articlenum,ArticleTitle,folderpath,teasertext from tblArticleList
where published='t'",Sqlconnection);
Sqlconnection.Open();
SqlDataReader dr=cmd.ExecuteReader();

while(dr.Read())
{
AddRSSItem(writer,dr.GetString (1),dr.GetString (2),dr.GetString
(3));

}

Sqlconnection.Close();
WriteRSSClosing(writer);

writer.Flush();
writer.Close();

Response.ContentEncoding = System.Text.Encoding.Unicode;
Response.ContentType = "text/xml";
Response.Cache.SetCacheability(HttpCacheability.Pu blic);

String FILENAME = Server.MapPath("La.xml");
StreamWriter objStreamWriter = File.AppendText(FILENAME);
//Response.Write (System.Text.Encoding.UTF8.GetString(ms.GetBuffer( )).TrimEnd());
objStreamWriter.Write(System.Text.Encoding.UTF8.Ge tString(ms.GetBuffer()).TrimEnd());

objStreamWriter.Close();


ms.Close();
}
Nov 11 '05 #1
2 2783
Oleg

I have been able to identify the problem althought i did not find a
solution.

The generated XML is simply perfectly formed BUT the XMLTextWriter
class adds some garbage caracters at the begining and then end(what i
believed to be spaces where strange characters i could not see in
notedpad)

Jonathan

Oleg Tkachenko <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message news:<uZ**************@TK2MSFTNGP12.phx.gbl>...
jonathan wrote:
I have a small and easy program that write a RSS.

Althought the generation works perfect, IE tells me it's not valid.

I get crazy because :
-removing a space at the end of the generated XML seems to help
-It refuses to read more than 5 items in the RSS

there is something i miss there in the XML. It drives me crazy.


Show us resulting XML (or better make it available on the Net).

Nov 11 '05 #2
"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:uY**************@tk2msftngp13.phx.gbl...
jonathan wrote:
The generated XML is simply perfectly formed BUT the XMLTextWriter
class adds some garbage caracters at the begining and then end(what i
believed to be spaces where strange characters i could not see in
notedpad)
The charcters at the beginning are probably unicode BOM - byte order mark.
Can you save your document and place it on the net for us to eb able to

see it? I hardly can say something without seeing those "garbage chars".


The problem may be this code:
StreamWriter objStreamWriter = File.AppendText(FILENAME);

objStreamWriter.Write(System.Text.Encoding.UTF8.Ge tString(ms.GetBuffer()).Tr
imEnd());
objStreamWriter.Close();
A) Why not just hand objStreamWriter to XmlTextWriter (objStreamWriter is an
instance of System.IO.StreamWriter which subclasses System.IO.TextWriter,
and XmlTextWriter has a constructor which takes a TextWriter)

B) Rewrite it like this:
Stream outStream = File.Open( FILENAME, FileMode.Append );
ms.WriteTo( outStream );
outStream.Close();
ms.Close();

-derek

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
Nov 11 '05 #3

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

Similar topics

9
by: lawrence | last post by:
Someone on www.php.net suggested using a seems_utf8() method to test text for UTF-8 character encoding but didn't specify how to write such a method. Can anyone suggest a test that might work?...
4
by: Alban Hertroys | last post by:
Another python/psycopg question, for which the solution is probably quite simple; I just don't know where to look. I have a query that inserts data originating from an utf-8 encoded XML file....
12
by: Mike Dee | last post by:
A very very basic UTF-8 question that's driving me nuts: If I have this in the beginning of my Python script in Linux: #!/usr/bin/env python # -*- coding: UTF-8 -*- should I - or should I...
38
by: Haines Brown | last post by:
I'm having trouble finding the character entity for the French abbreviation for "number" (capital N followed by a small supercript o, period). My references are not listing it. Where would I...
6
by: jmgonet | last post by:
Hello everybody, I'm having troubles loading a Xml string encoded in UTF-8. If I try this code: ------------------------------ XmlDocument doc=new XmlDocument(); String s="<?xml...
6
by: archana | last post by:
Hi all, can someone tell me difference between unicode and utf 8 or utf 18 and which one is supporting more character set. whic i should use to support character ucs-2. I want to use ucs-2...
7
by: Jimmy Shaw | last post by:
Hi everybody, Is there any SIMPLE way to convert from UTF-16 to UTF-32? I may be mixed up, but is it possible that all UTF-16 "code points" that are 16 bits long appear just the same in UTF-32,...
1
by: sheldon.regular | last post by:
I am new to unicode so please bear with my stupidity. I am doing the following in a Python IDE called Wing with Python 23. äöü äöü '\xc3\xa4\xc3\xb6\xc3\xbc' u'\xe4\xf6\xfc'...
10
by: Jed | last post by:
I have a form that needs to handle international characters withing the UTF-8 character set. I have tried all the recommended strategies for getting utf-8 characters from form input to email...
23
by: Allan Ebdrup | last post by:
I hava an ajax web application where i hvae problems with UTF-8 encoding oc chineese chars. My Ajax webapplication runs in a HTML page that is UTF-8 Encoded. I copy and paste some chineese chars...
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
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...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel

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.