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

How to create xml elements with special chars



Hi,

newbie that i am in .Net, i'm trying to add "D/T" as a new element in C#
:
XmlElement elemAttr =
(XmlElement)m_xmlDoc.AppendChild(m_xmlDoc.CreateEl ement("D/T" ) );

but the framework throws an XmlException ...

how do i overcome this ? do i have to parse the string for special chars
myself ?

please advise,

thanks , nim_co.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
6 4196
I don't think that you can. The XML standard limits the characters you can
use (http://www.w3.org/TR/xml11/#dt-element). Just like a compiler would
not allow the character "/" within a variable name.

Why would you want to do that anyway? If you could do what you want, you
would potentially confuse other standards like XPath which uses that symbol.
If you need special characters for presentation purposes, I would suggest
you rely on your code or move that information to an attribute or element
content.

"Nimrod Cohen" <ni****@hotmail.com> wrote in message
news:ul**************@TK2MSFTNGP11.phx.gbl...


Hi,

newbie that i am in .Net, i'm trying to add "D/T" as a new element in C#
:
XmlElement elemAttr =
(XmlElement)m_xmlDoc.AppendChild(m_xmlDoc.CreateEl ement("D/T" ) );

but the framework throws an XmlException ...

how do i overcome this ? do i have to parse the string for special chars
myself ?

please advise,

thanks , nim_co.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #2

Dear Peter,

I'm aware of the problematic aspect of that but as i vaugely recall
there are special indications for these character ( i.e : if i wanted to
use < i would have put &lt; instead... ) the question is if this is not
usable for the element name, and if so, does .net provides a parser ...

thanks,

Nim_co.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3
Nimrod Cohen wrote:
I'm aware of the problematic aspect of that but as i vaugely recall
there are special indications for these character ( i.e : if i wanted to
use < i would have put &lt; instead... ) the question is if this is not
usable for the element name, and if so, does .net provides a parser ...


In XML 1.0 element name cannot contain character "/" in any form, see
http://www.w3.org/TR/2000/REC-xml-20001006#NT-Name
You can use XmlConvert class to encode and decode element names.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #4
* Nimrod Cohen wrote in microsoft.public.dotnet.xml:
newbie that i am in .Net, i'm trying to add "D/T" as a new element in C#
:
XmlElement elemAttr =
(XmlElement)m_xmlDoc.AppendChild(m_xmlDoc.CreateE lement("D/T" ) );

but the framework throws an XmlException ...
Since "D/T" is not a legal XML element name.
how do i overcome this ? do i have to parse the string for special chars
myself ?


It is (or should be) impossible to overcome this.
Nov 12 '05 #5
can anyone be more descriptive and presumably say :

you can put special characters only in attribute values / inner texts
etc...
or explain what is the use of special character markers ( such as &_lt_;
etc ) if nobody suggested any solution that is using those... ?

isn't there a character that looks like & ?? ; and replaces "/" ??? can
it be used only inside values / inner text or also in names of elements
and attribute ?

Thanks again,

Nim_co.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #6
In article <eC**************@TK2MSFTNGP09.phx.gbl>, ni****@hotmail.com
says...
isn't there a character that looks like & ?? ; and replaces "/" ??? can
it be used only inside values / inner text or also in names of elements
and attribute ?


How about / will that do it for you?

There is a minor reference to HTML entities at :
http://www.big-rick.com/ref/asciiref.html

-- Rick
Nov 12 '05 #7

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...
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...
1
by: Ask Josephsen | last post by:
Hi I want to create an image with vertical text, but how do I handle special chars like "æøå"? I'm using php version 4.4.2. This is my code so far: $string = "æøå"; $fh = 6;
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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:
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
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...

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.