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 & 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 2 3184
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 & 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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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?...
|
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 =...
|
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...
|
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...
|
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
...
|
by: C# newbie |
last post by:
Hello group,
When I run an XPATH query first as:
//*[contains(translate(.,\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\",
\"abcdefghijklmnopqrstuvwxyz\")
|
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.
...
|
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....
|
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
|
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...
|
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
|
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...
|
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,...
|
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...
|
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,...
|
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: 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...
|
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...
| |