473,399 Members | 2,774 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,399 software developers and data experts.

Strings inside XML Tags


I'm placing the contents of numerous TextBoxes into an XML file.
However, problems occur when the user enters any 'special' characters
in the text boxes. For example, punctuation marks such as < > & ' "

And vice versa... if there are &lt; &gt; &amp; tags within the XML, is
there an easy way to convert these back to unicode characters for
display? (There seems to be hundreds of &xxxx; codes listed in the
specs.)

Is there a general purpose method somewhere that does this kind of
conversion? Thanks.

Roger

Nov 16 '05 #1
4 4123
Roger Helliwell wrote:

I'm placing the contents of numerous TextBoxes into an XML file.
However, problems occur when the user enters any 'special' characters
in the text boxes. For example, punctuation marks such as < > & ' "

And vice versa... if there are &lt; &gt; &amp; tags within the XML, is
there an easy way to convert these back to unicode characters for
display? (There seems to be hundreds of &xxxx; codes listed in the
specs.)

Is there a general purpose method somewhere that does this kind of
conversion? Thanks.

Roger

a CDATA section should do it. You can store everything including the
terminator of the CDATA section.
Nov 16 '05 #2
On 23 Jul 2004 03:14, Roger Helliwell wrote:

I'm placing the contents of numerous TextBoxes into an XML file.
However, problems occur when the user enters any 'special' characters
in the text boxes. For example, punctuation marks such as < > & ' "

And vice versa... if there are < > & tags within the XML, is
there an easy way to convert these back to unicode characters for
display? (There seems to be hundreds of &xxxx; codes listed in the
specs.)

Is there a general purpose method somewhere that does this kind of
conversion? Thanks.

Roger


If you set the XmlNode.InnerText property to a string containing these
characters it will convert them (e.g. > to &gt;) and convert back when
you read it out. If you set it's InnerXml property then it won't do that
and you then get problems.

--
Simon Smith
simon dot s at ghytred dot com
www.ghytred.com/NewsLook - NNTP Client for Outlook
Nov 16 '05 #3
On 23 Jul 2004 07:08:27 +0100 in
microsoft.public.dotnet.languages.csharp, Simon Smith
<gh*****@community.nospam> wrote:
If you set the XmlNode.InnerText property to a string containing these
characters it will convert them (e.g. > to &gt;) and convert back when
you read it out. If you set it's InnerXml property then it won't do that
and you then get problems.


When I read an XML file (using node.InnerText), the special characters
get converted. When I'm saving the XML though, no conversions are
being performed. I'm using WriteElementString() as below:

XmlTextWriter tw = new XmlTextWriter("myalbums.xml", null);
tw.WriteStartElement("albumlist");

foreach (CAlbum album in collection) {
tw.WriteStartElement("album");
tw.WriteElementString("title", album.Title); // special
characters will get saved in the XML
tw.WriteElementString("artist", album.Artist);
tw.WriteElementString("year", album.Year.ToString() );
tw.WriteElementString("duration", album.Duration.ToString() );
tw.WriteEndElement();
}
tw.WriteEndElement();

Any further ideas? Thanks.
Roger

Nov 16 '05 #4
On Fri, 23 Jul 2004 17:16:51 GMT in
microsoft.public.dotnet.languages.csharp, Roger Helliwell
<rh********@telus.net> wrote:
XmlTextWriter tw = new XmlTextWriter("myalbums.xml", null);
tw.WriteStartElement("albumlist");

foreach (CAlbum album in collection) {
tw.WriteStartElement("album");
tw.WriteElementString("title", album.Title); // special
characters will get saved in the XML
tw.WriteElementString("artist", album.Artist);
tw.WriteElementString("year", album.Year.ToString() );
tw.WriteElementString("duration", album.Duration.ToString() );
tw.WriteEndElement();
}
tw.WriteEndElement();


I see the problem now. WriteElementString() doesn't convert special
characters to character entities.
WriteString() does.

Roger

Nov 16 '05 #5

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

Similar topics

2
by: Muumac | last post by:
I have problem with large textfiles! When I load over 4MB xml and then try to preg_match something in this I get always FALSE! I have <File>....</File> tags in XML. Between tags is files contents...
16
by: Paul Prescod | last post by:
I skimmed the tutorial and something alarmed me. "Strings are a powerful data type in Prothon. Unlike many languages, they can be of unlimited size (constrained only by memory size) and can hold...
3
by: jjliu | last post by:
Could someone tell me how to parse the inside of html tags by perl, such as <meta> </meta> <head> </head> <title> </title> ......... Thanks
5
by: Lou | last post by:
How do I add help strings to my .dll functions in C# -Lou
11
by: julien | last post by:
Hello, I posted this question on the NDoc-user mailing list, but it looks like a dead list (no messages for 10 days!). I'd like to use NDoc tags or custom tags inside methods like: void...
10
by: Xah Lee | last post by:
there's a HTML odditity. That is, line break will be ignored inside <preif the adjacent lines are tags. see the source code and description here: http://xahlee.org/js/linebreak_after_tag.html...
1
by: CapRand | last post by:
Hi, I am creating an ASP.NET site and have created a form which I have been able to dynamically with listboxes, labels etc from a database - using mainly form1.Controls.Add ..... Does anyone...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.