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

InnerXML and InnerText BOTH don't work right

I'm trying to get some text into an XMLElement that may or may not
contain markup, and it may or may not contain characters that need
escaping. I want the special characters escaped, but I want to preserve
the markup. This is so a user can enter some text with (xml
compatible) HTML tags and have it render properly (via XSLT) without
having to know about escaping the ampersand. For example, I want to
take the text:

"Nice t-shirt <p/> Cool & Stylish"

And put it in an element as such:

<ItemDescription>
Nice t-shirt <p/> Cool &amp; Stylish
</ItemDescription>

InnerXML chokes on the ampersand, and innerText escapes the tags. How
can I do this? I'm "manually" escaping the ampersand (and
apostrophies) in my code right now, and using innerXML, but it seems
like this must be a very common thing to want to do, and doing it
manually is error prone and more complex than it needs to be,
especially if the text might also have < or > that are not parts of
tags. I can't find any other properties on XMLElement that will do
this. There must be a way to do it directly.

--Kyle Bennett

Nov 12 '05 #1
2 3179
CDATA tags

--
2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.masterado.net/home/listings.aspx

"kben" <th*****************@comcast.net> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
I'm trying to get some text into an XMLElement that may or may not
contain markup, and it may or may not contain characters that need
escaping. I want the special characters escaped, but I want to preserve
the markup. This is so a user can enter some text with (xml
compatible) HTML tags and have it render properly (via XSLT) without
having to know about escaping the ampersand. For example, I want to
take the text:

"Nice t-shirt <p/> Cool & Stylish"

And put it in an element as such:

<ItemDescription>
Nice t-shirt <p/> Cool &amp; Stylish
</ItemDescription>

InnerXML chokes on the ampersand, and innerText escapes the tags. How
can I do this? I'm "manually" escaping the ampersand (and
apostrophies) in my code right now, and using innerXML, but it seems
like this must be a very common thing to want to do, and doing it
manually is error prone and more complex than it needs to be,
especially if the text might also have < or > that are not parts of
tags. I can't find any other properties on XMLElement that will do
this. There must be a way to do it directly.

--Kyle Bennett

Nov 12 '05 #2
kben wrote:
I'm trying to get some text into an XMLElement that may or may not
contain markup, and it may or may not contain characters that need
escaping.
Sorry, but that's oxymoron. Text is text and markup is markup, you can't
have either-text-or-markup.
"Nice t-shirt <p/> Cool & Stylish"
This is looks like malformed XML or HTML. Whoever generates it - you
better get it fixed.
InnerXML chokes on the ampersand, and innerText escapes the tags.


That's by design. InnerXML expects XML and InnerText - text.
You can try reading such malformed XML via SgmlReader to get it
wellformed and then appends to XmlElement as XML.

--
Oleg Tkachenko [XML MVP, MCP]
http://blog.tkachenko.com
Nov 12 '05 #3

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

Similar topics

6
by: Philipp Lenssen | last post by:
Why isn't there a way in standard DOM to access all XML of a node? (Similar to what outerHTML and innerHTML can do on Firefox or Internet Explorer when accessing HTML.) Or am I missing something?...
13
by: Julia Peterwitz | last post by:
I have a function that works with explorer but not with netscape. The problem is the function at line 5. 1 fSetSelectedDay(myElement){ 2 /* 3 ... 4 */ 5 var elementText =...
13
by: Jeff | last post by:
Hi! I'm trying to update a number in a document with the following code. It displays a number, a div block with a minus sign and a div block with a plus sign. When I click the plus sign I want...
2
by: delraydog | last post by:
I know that innerText is not supported in FireFox and I've found the following code fragment which was originally designed in an HTMLElement prototype for an innerText getter. I do not however want...
3
by: Martin Madreza | last post by:
hello, i despair on one simple problem (maybe it's to simple???) I have the string txt = "hallo</hmm>" or txt = "am&24" and want to pass it to the XmlNode InnerXml property ...
6
by: C# newbie | last post by:
Hello group, When I run an XPATH query first as: //*[contains(translate(.,\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\", \"abcdefghijklmnopqrstuvwxyz\")
1
by: ALI-R | last post by:
I am showing the InnerXml of a node (in a treeView Control) in a tooltip ,but it is not formatted well ,all the elements after each other ,is there a way to format the innertext in a tooltip. ...
13
by: Lyners | last post by:
I have a web page writen in ASP.NET that contains some javascript so that when a user presses a button, or edits a certain field in a datagrid, another cell in the datagrid is filled with a value....
1
by: SMichal | last post by:
Hi, is there some posibility how to read inner text from IFRAME on server-side ? I've tested it with innerText and InnerHtml but it doesnt work
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.