473,804 Members | 2,719 Online
Bytes | Software Development & Data Engineering Community
+ 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 16824
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_De tails> (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_De tails> (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.co m> wrote in message
news:Os******** *****@TK2MSFTNG P14.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.co m> wrote in message
news:Os******** *****@TK2MSFTNG P14.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.co m> wrote in message
news:Os******** *****@TK2MSFTNG P14.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.co m> 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.co m>
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.co m> wrote in message
news:eV******** ******@TK2MSFTN GP14.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.co m> wrote in message
news:Os******** *****@TK2MSFTNG P14.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
24129
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 convert n = "" # init new string for i in str: if i in chr: # if special character in str n+='\\' # append it with a backslash n+=i
6
2795
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 hyphens, german umlauts, etc. i could write a function to parse the comment and substitute special chars with the relevant html code, but maybe this already exists in some
6
3994
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: -------------------------------------------------- <?xml version="1.0"?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html>
0
1847
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 - so I have to find the entry in my db, where the page title is guestbook. But there isn't a only column for this virtual filenames, but only entries like "Guestbook", "This & much more..." and so on. Becaus I'm not able to use "This & much...
2
1649
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
2654
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 aware, that's connected with the way the GET method passes variable values, but I don't know how to make GET to take the variable value "as it is" without interpreting special chars as special chars. So, how should I send GET variables in order not...
3
10172
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 avoided? The reason being that I compare this string to a string in an Access DB (btw, Access also screws up with the character by replacing "Ñ" with "-"). So when I compare these two strings, they won't match because both systems storing the data...
8
2919
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 nothing works . I have no idea how to go further . Can anyone help me ? Thanks in advance.
5
4164
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 points to a sqlserver2005 instance... it comes in looking like this in the debugger:
0
9706
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10569
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10315
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10075
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7615
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.