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

XmlTextWriter

I am using the XmlTextWriter class to generate some XML however if I
try to do something like

string str = "cost £500";
xtw.WriteElementString("symbol", str);

The £ does not get encoded to £ like it should. I have tried
changing the encoding of it but none of the options (Unicode, UTF8
etc.) perform the encoding correctly.

At the moment I have just replaced the above with

xtw.WriteStartElement("string");
str = "cost £500";
str = str.Replace("£", "£");
xtw.WriteRaw(str);
xtw.WriteEndElement();

Which does the trick but any other characters that need encoding will
have to be added to the str = str.Replace("£", "£"); line. Is
there anything to perform this encoding automatically?

Thanks in advance,

Rob.
Nov 11 '05 #1
4 1853
Robert Walter wrote:
I am using the XmlTextWriter class to generate some XML however if I
try to do something like

string str = "cost £500";
xtw.WriteElementString("symbol", str);

The £ does not get encoded to £ like it should.

Why do you think it should do that? What's so special in £ character?
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2
Oleg Tkachenko <oleg@NO SPAM PLEASEtkachenko.com> wrote in message news:<Oq**************@TK2MSFTNGP12.phx.gbl>...
Robert Walter wrote:
I am using the XmlTextWriter class to generate some XML however if I
try to do something like

string str = "cost 500";
xtw.WriteElementString("symbol", str);

The does not get encoded to £ like it should.

Why do you think it should do that? What's so special in character?


It should do that 'cause if you put a pound symbol in an XML document
it's not valid.
Nov 11 '05 #3
Robert Walter wrote:
It should do that 'cause if you put a pound symbol in an XML document
it's not valid.

Not really. Pound symbol is allowed in XML documents as thousands of other
unicode symbols, try yourself: http://www.tkachenko.com/temp/source.xml

The only two symbols must be escaped in XML: & and <.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #4
Hello!

If you specify the correct encoding in the XML document declaration, it'll
display itself as a valid document. Did you try that?

--
venlig hilsen / with regards
anders borum
--
Nov 11 '05 #5

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

Similar topics

5
by: Jain, Pranay Kumar | last post by:
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...
1
by: Koray Atsan | last post by:
Hi All I have a simple question as i am a newbie in xml. I am using XmlTextWriter to write some values to an xml file . I use XmlTextWriter textwriter = new XmlTextWriter ("path",null); to create...
3
by: Magnus | last post by:
can anyone help me on how to create and manipulate a xmttextwriter without having to craete a physical file. I have an application that should return data in xml. But I do not want to create a...
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...
3
by: K Rege | last post by:
Hi there, I tried to implement a little XML-EchoServer using Sockets and XmlTextWriter/Reader. However the server hangs while reading the input from the client (wr.Flush() seams not to work). I...
1
by: Riko Eksteen | last post by:
Hi I'm reading an xml file into an XmlDocument, adding some nodes, and writing it back out. I would like the nodes I add to assume the same level of indeting as the rest of the document. (I load...
2
by: Steve | last post by:
I'm an XML newb. I'm serializing a class and when I inspect the xml file, all the data is on one line rather than being nested and indented Is that normal? <code> StreamWriter sw = new...
4
by: Einar Høst | last post by:
Hi, I'm having weird problems using StringWriter and XmlTextWriter. My code looks like this: StringWriter sw = new StringWriter(CultureInfo.InvariantInfo); XmlTextWriter xtw = new...
4
by: quest | last post by:
Is there anyway I can generate the xml in the following format using XmlTextWriter ? Intended output: <?xml version="1.0" ?> I tried: XmlTextWriter xmlWriter = new...
3
by: GaryDean | last post by:
I'm using an XmlTextWriter and it's various methods such as WriteElementString, WriteStartElement, WriteEndElement, etc to create an xml document. When I instantiate the XmlTextWriter to a file......
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
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: 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:
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.