473,471 Members | 1,981 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Escaping special chars in XML

Hello,

I'd like to have the following structure in my XML file

<lname, _fname, _minit>
<status>it is all good</status>
</lname, _fname, _minit>

But apparently, there is a problem with commas and underscores being in
the key name of the node. How can I escape it?

Thanks.
Mar 5 '06 #1
8 16800
Frank,
This documentation page details exactly what is and is not allowed in an
XmlElement name:
http://msdn2.microsoft.com/en-us/library/35577sxd.aspx

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Frank Rizzo" wrote:
Hello,

I'd like to have the following structure in my XML file

<lname, _fname, _minit>
<status>it is all good</status>
</lname, _fname, _minit>

But apparently, there is a problem with commas and underscores being in
the key name of the node. How can I escape it?

Thanks.

Mar 5 '06 #2
Peter Bromberg [C# MVP] wrote:
Frank,
This documentation page details exactly what is and is not allowed in an
XmlElement name:
http://msdn2.microsoft.com/en-us/library/35577sxd.aspx


Thank you. However, following those rules, something like this:

<order details> would be encoded as <Order_x0020_Details> (e.g. space
converted to hex plus underscore before and after). When I load the
file into IE, it doesn't convert _x0020_ to an actual space. So I am
confused as to how I should encode spaces and commas when they appear in
the name of the tag.

Thanks.
Mar 5 '06 #3
In two words, you can't. spaces and commas simply aren't allowed in XML
element names. What exactly is it that you hope to accomplish? Certainly
there must be another way to get there... If the idea is to be able to parse
the element name as if it were some CSV delimited format, all you would need
to do is use the uderscore and /or some other "legal" character as the
delimters.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Frank Rizzo" wrote:
Peter Bromberg [C# MVP] wrote:
Frank,
This documentation page details exactly what is and is not allowed in an
XmlElement name:
http://msdn2.microsoft.com/en-us/library/35577sxd.aspx


Thank you. However, following those rules, something like this:

<order details> would be encoded as <Order_x0020_Details> (e.g. space
converted to hex plus underscore before and after). When I load the
file into IE, it doesn't convert _x0020_ to an actual space. So I am
confused as to how I should encode spaces and commas when they appear in
the name of the tag.

Thanks.

Mar 5 '06 #4

"Frank Rizzo" <fr****@notn.com> wrote in message
news:Os*************@TK2MSFTNGP14.phx.gbl...
Hello,

I'd like to have the following structure in my XML file

<lname, _fname, _minit>
<status>it is all good</status>
</lname, _fname, _minit>

But apparently, there is a problem with commas and underscores being in
the key name of the node. How can I escape it?


You can't; those characters are not legal in element names. See
http://www.w3.org/TR/REC-xml/#sec-starttags for the exact rules, but
roughly:

1. The first character must be a letter or an underscore
2. The rest can be a letter, a digit, an underscore, a dot, or a dash

The BNF expansions list colons too, but nowadays colons are reserved for
expressing namespaces.

Can you use dots instead of commas?
Mar 5 '06 #5
Element names are not meant to store data, only to identify the data.

It might be better to do something like

<person>
<fname>xxx</fname>
<lname>xxx</lname>
<status>xxx</status>
</person>

"Frank Rizzo" <fr****@notn.com> wrote in message
news:Os*************@TK2MSFTNGP14.phx.gbl...
Hello,

I'd like to have the following structure in my XML file

<lname, _fname, _minit>
<status>it is all good</status>
</lname, _fname, _minit>

But apparently, there is a problem with commas and underscores being in
the key name of the node. How can I escape it?

Thanks.

Mar 5 '06 #6
But I can still escape spaces as _x0020_ and comma= _x002c_
Can't I use those in element names?

Mike Schilling wrote:
"Frank Rizzo" <fr****@notn.com> wrote in message
news:Os*************@TK2MSFTNGP14.phx.gbl...
Hello,

I'd like to have the following structure in my XML file

<lname, _fname, _minit>
<status>it is all good</status>
</lname, _fname, _minit>

But apparently, there is a problem with commas and underscores being in
the key name of the node. How can I escape it?


You can't; those characters are not legal in element names. See
http://www.w3.org/TR/REC-xml/#sec-starttags for the exact rules, but
roughly:

1. The first character must be a letter or an underscore
2. The rest can be a letter, a digit, an underscore, a dot, or a dash

The BNF expansions list colons too, but nowadays colons are reserved for
expressing namespaces.

Can you use dots instead of commas?

Mar 6 '06 #7
Frank Rizzo <fr****@notn.com> wrote:
But I can still escape spaces as _x0020_ and comma= _x002c_
Can't I use those in element names?


You can, but you'll have to unescape them yourself.

As Peter said, you shouldn't really be doing this - it very much feels
like you're using the element name to store data rather than just to
identify data.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 6 '06 #8
Don't let the web page quoted about mislead you. If you do that, it's not
"escaping" in the sense that C# escapes backslash as \\.. It's not a
standard, and no program, other than anything you might write, will see a
relationship between space and _x0020_.

"Frank Rizzo" <fr****@notn.com> wrote in message
news:eV**************@TK2MSFTNGP14.phx.gbl...
But I can still escape spaces as _x0020_ and comma= _x002c_
Can't I use those in element names?

Mike Schilling wrote:
"Frank Rizzo" <fr****@notn.com> wrote in message
news:Os*************@TK2MSFTNGP14.phx.gbl...
Hello,

I'd like to have the following structure in my XML file

<lname, _fname, _minit>
<status>it is all good</status>
</lname, _fname, _minit>

But apparently, there is a problem with commas and underscores being in
the key name of the node. How can I escape it?


You can't; those characters are not legal in element names. See
http://www.w3.org/TR/REC-xml/#sec-starttags for the exact rules, but
roughly:

1. The first character must be a letter or an underscore
2. The rest can be a letter, a digit, an underscore, a dot, or a dash

The BNF expansions list colons too, but nowadays colons are reserved for
expressing namespaces.

Can you use dots instead of commas?

Mar 6 '06 #9

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

Similar topics

14
by: tertius | last post by:
Is there a better way to append certain chars in a string with a backslash that the example below? chr = "#$%^&_{}" # special chars to look out for str = "123 45^ & 00 0_" # string to...
6
by: Jonas Meurer | last post by:
hello, my script selects a comment saved as VARCHAR in MySQL and displays it inside an html page. the problem is, that the comment contains several special characters, as mysterious utf-8...
6
by: Horst Gutmann | last post by:
Hi :-) I currently have quite a big problem with minidom and special chars (for example &uuml;) in HTML. Let's say I have following input file:...
0
by: Steffen Gebert | last post by:
Hello, I want to fetch the page via php from a mysql-db, which is called by an emulated filename (mod_rewrite, but that might be unimportant). So I have a file, which is called by guestbook.html...
2
by: Thorsten Viel | last post by:
Hi List, im trying to use special chars with the std::string (like S) but when i cout<< the string the special chars have disappeared. What's wrong here? Thanks in advance
4
by: dutch disCo | last post by:
Hi, I'm trying to use GET method to pass variables through my script files. Unfortunately, when a special char (&, ?, +) is being posted the variable gets trimmed in a very strange way. I'm...
3
by: VMI | last post by:
When I execute a ReadLine from an ascii file with special chars (ie. the 'Ñ' in "NUÑEZ PEREZ"), it automatically deletes this character. So "NUÑEZ PEREZ" becomes "NUEZ PEREZ". How can this be...
8
by: abhi147 | last post by:
Hi , I have been trying to convert a 32 bit string like "b2a4fdf15af7c4f215e1909be4707bdb" to convert to a string of special chars like "²¤ýñZ÷Äòá?›äp{Û" I have tried a lot of things .. but...
5
by: Alex | last post by:
Hi all - Is there a standard way to handle special chars in strings in dotnet? I'm using csharp and having two seperate problems... 1. Passing in args... I need to pass in an arg that...
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
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
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...
0
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...
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,...
1
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...
0
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...
0
muto222
php
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.