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

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 1917
In article <e2**********@nyytiset.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
In article <4a************@individual.net>,
Peter Flynn <re*********@m.from.email.address> wrote:
If you think tags and elements are the same thing you are already in
considerable trouble.


I believe many people have successfully used XML while labouring under
this misapprehension.

-- Richard
Apr 17 '06 #11
Richard Tobin wrote:
In article <4a************@individual.net>,
Peter Flynn <re*********@m.from.email.address> wrote:
If you think tags and elements are the same thing you are already in
considerable trouble.


I believe many people have successfully used XML while labouring under
this misapprehension.


I'm sure they have. But they probably haven't needed to refer to them
by name :-)

///Peter
Apr 17 '06 #12

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

Similar topics

3
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...
6
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...
2
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: ...
1
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...
7
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...
3
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...
1
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"...
2
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...
7
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...
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: 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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.