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:
<ItemDescriptio n>
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 3193
CDATA tags
--
2005 Microsoft MVP C#
Robbe Morris http://www.robbemorris.com http://www.masterado.net/home/listings.aspx
"kben" <th************ *****@comcast.n et> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.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:
<ItemDescriptio n> 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?
--
Google Blogoscoped
http://blog.outer-court.com
|
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 = eval(myElement.children.innerText);
6 /*
|
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 the number to add one to
itself, and when I press minus I want it to subtract one.
This works in Internet Explorer, but nothing happens in Mozilla.
Can any bright head here spot what I'm doing wrong? What here might
|
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 to use the
getter approach and want to just get the innerText as follows:
var childS = iframe.contentWindow.document.body.childNodes;
for(var i=0; i<childS.length; i++)
{
if(childS.nodeType==1)
text+= childS.tagName=="BR" ? '\n' :...
|
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
myNode.InnerXml = txt //error
| |
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.
=========Code==========
private void tvTreeView_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e){
string strTemp="";
int i=0;
|
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.
My probelm.... when I have the user press the update button (which does a
post back that loops through the datagrid and updates a database) the
field/cell that is filled by the javascript appears to be blank in my update
code, even though I can...
|
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: 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...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |