473,587 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML file and & character as data

Hello,

I have a XML file using Iso 8859-1 encoding.
Every time when I try to put & character as Tag's value
like <tag>This is & character</tag> Exception is shown
in my application. I use XMLDocument reader in .NET platform.

How should people code & character as an ordinary data character?
I don't mean any platform dependent solution just XML's point of view.

Cheers!

Apr 17 '06 #1
11 1942
In article <e2**********@n yytiset.pp.htv. fi>, BenI <be*****@yahoo. com> wrote:
I have a XML file using Iso 8859-1 encoding.
It's nothing to do with the encoding.
Every time when I try to put & character as Tag's value
like <tag>This is & character</tag> Exception is shown
in my application.


& is used in XML for entity references. To get the ampersand
character, you have to type "&amp;", for example:

<tag>This is &amp; character</tag>

-- Richard
Apr 17 '06 #2
BenI wrote:
Hello,

I have a XML file using Iso 8859-1 encoding.
Every time when I try to put & character as Tag's value
like <tag>This is & character</tag> Exception is shown
in my application. I use XMLDocument reader in .NET platform.

How should people code & character as an ordinary data character?
I don't mean any platform dependent solution just XML's point of view.

Cheers!

Use the escape code &amp;

Steve
Apr 17 '06 #3
Richard Tobin wrote:
& is used in XML for entity references. To get the ampersand
character, you have to type "&amp;", for example:


Or use a numeric character escape, & or &#x26;.

You'll also need to do this for the < and > characters (&lt; and &gt;).

Note that if you're manipulating the data through an XML API such as SAX
or DOM, conversion between the character and its XML escaped version, or
vice versa, will be handled automagically for you.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Apr 17 '06 #4
Joseph Kesselman said the following on 17-04-2006 17:12 +0200:
Richard Tobin wrote:

& is used in XML for entity references. To get the ampersand
character, you have to type "&amp;", for example:


Or use a numeric character escape, & or &#x26;.

You'll also need to do this for the < and > characters (&lt; and &gt;).


And single and double-quotes, see:

"What are the special characters in XML?"
http://xml.silmaril.ie/authors/specials/

--
Regards
Harrie
Apr 17 '06 #5
Harrie wrote:
And single and double-quotes


When they appear within attributes quoted with that same character, yes.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Apr 17 '06 #6
Harrie <sp*****@linux. org.invalid> wrote:
You'll also need to do this for the < and > characters (&lt; and &gt;).


And single and double-quotes, see:

"What are the special characters in XML?"
http://xml.silmaril.ie/authors/specials/


This is going too far. You are saying that we need to escape all of these
characters. The cited document explains the situation better. The details are
somewhat complicated, but the short story is (using the loose word "escaped"
to mean "written as an entity reference or as a character reference"):

1) "&" must always be escaped when not used in its special XML meaning
2) "<" must always be escaped when not used in its special XML meaning
3) ">" does not need to be escaped, but may be escaped when not used
in its special XML meaning; in CDATA sections, it must be escaped
for compatibility
4) the Ascii quotation mark " does not need to be escaped (but may be escaped
when not used as an attribute value delimiter), except in the special case
where it appears inside an attribute value delimited by Ascii quotation
marks
5) similarly for the Ascii apostrophe '.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Apr 17 '06 #7
BenI wrote:
Hello,

I have a XML file using Iso 8859-1 encoding.
Every time when I try to put & character as Tag's value
See http://xml.silmaril.ie/authors/makeup/
If you think tags and elements are the same thing you are already in
considerable trouble.
like <tag>This is & character</tag> Exception is shown
in my application. I use XMLDocument reader in .NET platform.

How should people code & character as an ordinary data character?


&amp;

///Peter
--
XML FAQ: http://xml.silmaril.ie/
Apr 17 '06 #8
On Mon, 17 Apr 2006, Peter Flynn wrote:
If you think tags and elements are the same thing you are already in
considerable trouble.


See http://www.flightlab.com/~joe/sgml/faq-not.txt part 5.

Sorry, but that really was inevitable. :-}
Apr 17 '06 #9
Jukka K. Korpela said the following on 17-04-2006 19:23 +0200:
Harrie <sp*****@linux. org.invalid> wrote:
You'll also need to do this for the < and > characters (&lt; and &gt;).
And single and double-quotes, see:

"What are the special characters in XML?"
http://xml.silmaril.ie/authors/specials/
This is going too far. You are saying that we need to escape all of these
characters. [..]


I didn't intend to say that, I should have thought longer about my
words; I see my error, thanks for the correction.
[..] The cited document explains the situation better.


That's why I provided the link, I wanted to help the OP understand which
five character have special meaning in XML, but my very short post
missed it's point.

--
Regards
Harrie
Apr 17 '06 #10

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

Similar topics

3
6001
by: wenke | last post by:
Hi, I am using the following code (see below) from php.net (http://www.php.net/manual/en/ref.xml.php, example 1) to parse an XML file (encoded in UTF-8). I changed the code slightly so that the cdata sections will be echoed an not the element names as in the original example. In the cdata sections of my XML file I have terms like this:
6
6236
by: Rizwan | last post by:
I have the following tasks : 1) receive a flat text file which contains data and 2) convert it into an XML The flat text file for example is in this format : 1 2 1234567890123456789012345
2
2051
by: Yosh | last post by:
Morning! I am developing an winform application in c#. I have an app.config file that contains an entry with a Url address assigned to it. When I run my application I get the following error: The ':' character, hexadecimal value 0x3A, cannot be included in a name. After doing some research, the problem is not the semi-colon. It's the...
1
6743
by: Magnus | last post by:
allrite folks, got some questions here... 1) LAY-OUT OF REPORTS How is it possible to fundamentaly change the lay-out/form of a report in access? I dont really know it that "difficult", but listen up; Reports, the way I look at them, all present data downwards, in this way; TITLE data
7
7309
by: Sascha Schmidt | last post by:
Hello ! I have a little problem accessing a Visual Foxpro-database using ODBC (Driver 6.00.8167) (using System.Data.Odbc). Reading a column, defined in the Foxpro table definition as a kind of binary char (i'm no foxpro-expert and the database is predetermined) and containing Unicode-String, delivers a byte structure in the resulting...
3
8522
by: Billy Smith | last post by:
I'm trying to write a little utility that will write some binary data to a file via a javascript and Windows Script Host under Windows XP. The only way to do this that I can find is to convert the binary data to text via String.fromCharCode() function and then write to the file with TextStream.Write(). But that function gives an "invalid...
1
6466
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located...
2
7692
by: Bina | last post by:
hi, I want to read & write a html file which contain the japanese character. Now how i will do it?I can read & write english character . but when i read & write Japanese character from the html file then the writed html file cannnot show the japanese character. my new created html file show the another character, it cannot show the original...
7
3657
by: JB | last post by:
Hi everyone, I'm having problems with Tab characters in an XML file. I want to store a Tab character as part of an element value e.g. <Separator>TAB</Separator> I'm using XmlWriter to write my file and XmlReader to read it. At first my tab character was stored in the element, but was ignored when it was read back (giving me an empty...
0
7920
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7849
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8215
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8347
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7973
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5394
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1454
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.