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

0
4/20/2005 9:36:56 PM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
802 Views

Similar Articles

[PageSpeed] 56

CDATA tags

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



"kben" <thismailisneverread@comcast.net> wrote in message 
news:1114033016.344355.13760@z14g2000cwz.googlegroups.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
> 


0
info8687 (7)
4/25/2005 11:33:19 PM
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
0
Oleg
5/1/2005 10:58:34 AM
Reply:

Similar Artilces:

search for right
Hi all, I wonder if there's any possibility to do the following without rearranging my tables: I'd like to look up an order number in a table, and get the price from two coloumns _left_ So the order number is in C3 and I'd like to get the value in A3 and so on. Vlookup does only to right... Please advise, Thanks, Marton =INDEX(A1:A100,MATCH(ord_num,C1:C100,0)) -- HTH RP (remove nothere from the email address if mailing direct) "VilMarci" <dontsend@here.com> wrote in message news:eHlKiP6VFHA.3764@TK2MSFTNGP15.phx.gbl... > Hi all, > > I wonder if...

Default mailbox rights #2
Hello, Is there an MS white paper that shows the specific default special permissions found in AD Users and Computers - Exchange Advanced - Mailbox Rights? Thank you, JVM Try these two articles: http://support.microsoft.com/kb/328229/en-us http://www.microsoft.com/technet/prodtechnol/exchange/guides/E2k3ADPerm/cc98c853-7bd2-47bc-b88f-36163f1306f1.mspx Nue "J Meyer" <JMeyer@discussions.microsoft.com> wrote in message news:890E6D32-C501-45E2-BD57-6E036DD8D3CC@microsoft.com... > Hello, > > Is there an MS white paper that shows the specific default special > p...

How to Clear or Reconcile without right-click
How does one Clear or Reconcile the currently selected transactcion without going through the tedium of right- clicking and selecting Mark As -> Cleared (or Reconciled)? Thanks CTRL-SHIFT-M "MoneyUser" <anonymous@discussions.microsoft.com> wrote in message news:1a72401c41db7$b7003000$a101280a@phx.gbl... > How does one Clear or Reconcile the currently selected > transactcion without going through the tedium of right- > clicking and selecting Mark As -> Cleared (or Reconciled)? > > Thanks In microsoft.public.money, MoneyUser wrote: >How does one Cl...

OWA stopped working on one of the Cluster Nodes
Our environment has 2 FE servers and an A/A/P cluster. Recently (not sure how long ago) OWA stopped allowing logons on one of the BE nodes. I have checked the configuration for the HTTP resources and they all appear to be identical. When I move the EVS from the Active to Passive node OWA starts working properly. I had installed Symantec's SMSMSE 4.6 around the same time frame and have since removed that. I have tried to Restore the IIS configuration to an earlier date and that fixed the Passive Node but not the Active node. I have removed Exchange and reinstalled and removed IIS and...

Record Macro Relative does not work?
Can someone help me with this macro. I want to go to any cell of my choice and press f2 to edit, then go to the fifth character of that cell, then select the next 6 characters and change them to a smaller font size (8), then "enter". I tried to make this macro using the record macro function, but it did not work how I want it to. It ends up pasting the contents of the cell which I used to record the macro initially. Can this kind of macro be done? To get a relative recorded macro, make sure the stopr recording toolbar is visible, it has 2 icons, one is to s...

Reply rule doesn't work consistantly
I've got an Outlook 2003 client and we are trying to setup a rule to emulate the Out of Office Assistant. I've setup a rule that is supposed to send reply with a template if the sender is from a list of contacts that I've chosen. It isn't working as expected. The first time I tried it, I entered only one (internet) email address which worked perfectly. If I add any addresses to that list, it doesn't work anymore - the reply is not sent. I know that it can reply to internet email addresses, since it worked that one time, but I can't figure out why it won't work when...

Why doesn't the page preview have the same order as work page?
Why doesn't the preveiw page look like the one I built on the work pages. I have "saved as" and "saved. The nagagation bars in preview goes to different pages than titled. HELP!!!!!! ...

Double Click on file and mouse not working
Good afternoon, thanks for taking time to look at my problem. I am trying to open a word document by double clicking on the file name in "my documents". Word opens, but not the document. If you go into File and Open, you can open the document, but the mouse cursor will not go anywhere in the document. I have tried to open Word in safe mode, blasted the normal.dot, copied a normal.dot from another computer, heck I tried disassociating doc from Word. Nothing worked. I even installed Windows Live so I could uninstall it. I'm hoping someone has fixed this problem. ...

DCount?? not working. Pls help
My data is orgnaised as follows: A B C D E David 2245 abcd efgh ijk Susan 2249 xyz etc etc Mickey 1234 etc 123 etc Arnold 4321 etc.... David 1441 Mickey abcd etc etc I want to count the number of non blank cells in B for each "David", "Susan" etc in A, and have the value returned in another sheet. I tried DCount, but it doesnt seem to be working. -- KDDXB I mocked up your data as you provided it, with names in A1:A6 etc. I entered "David" in A8 and this formul...

Can't get Date Range to work from Form to Report
Hi, I've followed Allen Browne's directions very closely for creating a form for a date range to limit results to that date range on a report and can not get it to work for some reason. I've read many threads on this board which all say the same thing and it seems to work for everyone else. :( Here's what I have: A form with two unbound text boxes called [txtDateBegin] and [txtDateEnd]. The form is called "frmDateRange" and the report is called "Sales Activity Report". The two unbound text boxes are set to "Short Date" format which the user ...

SendTo PDF Not Working on GP 10
I upgraded a client from GP 8.0 to GP 10.0. Since the ugprade, they are unable to use the SendTo PDF option from within GP. We have tried reinstalling Adobe and that hasn't changed anything. The users can see the PDF being created but a blank email doesn't open from their email client as it used to. The client is on version 10.00.0991 and I thought this issue was to be resolved in 10.0 SP 1 but obviously it hasn't been for us. The client is also using Outlook. Is this still a bug with 10.0 or are we missing something? I am on Adobe Acrobat Standard 8.0 with Microsoft ...

Insert list of figures does not work for Pictures
Version: 2004 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel I can generate a list of all of my inserted objects by caption: Figure, Example, Table, Song, Chart. But when I try to generate a list of the pictures I have inserted (caption reads Picture ...), I get the following message: Error! No table of figures entries found. It's as if the macro that reads the caption list doesn't have Picture in its internal dictionary. I do have the Picture captions in a text box that is formatted as "tight" to allow text-wraparound; could that be causing the problem? If so h...

Money Stopped Working Problem Solved! (or at least explained)
After the SP1 update my Money Plus Deluxe on Vista Ultimate would "stop working" when I selected Portfolio or Help. It turns out that the problem was a conflict with my Roboform program which is a password fill-in program that attaches itself to web pages in order to automatically enter my personal information. Because Portfolio and Help look like web pages to Roboform, it tries to attach and apparently crashes Money. If I stop Roboform before starting Money all is well. Alternatively, I can start Money "as administrator" and that will work too. In microsoft.publi...

Setting up email to work
I created a webpage for my company and when I created the send button I went into Format Form Properties and selected Submit and then went to Form Properties. I then selected Send Data to me in Email and entered in a valid Email. However when I go to test the web page and I enter in the required information and I click Send I get a The Page Cannot Be Displayed error and HTTP 405 - Resource not allowed. What do I do? Reference: "Publisher web publication forms 101": http://msmvps.com/blogs/dbartosik/archive/2006/01/07/80564.aspx DavidF "Russ" <Russ@discussions.mic...

Function for convertion of leters doesn't work.
I'm using function LOWER to convert string i my table on small size but Access gives me a message that the function is not defined.Please, do you know another function? MS Access does not have a LOWER function. Try LCase() instead. -- Cheryl Fischer Law/Sys Associates Houston, TX "Stenli" <svet2000@seznam.cz> wrote in message news:10b201c3626e$b613a050$a301280a@phx.gbl... > I'm using function LOWER to convert string i my table on > small size but Access gives me a message that the function > is not defined.Please, do you know another function? ...

Coments on a Work Order
Hello I have been using the system for almost 2 years, and the following error, which began after I install SP 1.3, is driving me crazy. I sell items that require serial numbers. I had added the term "S/N:" on SubDescription 1 for some items. This is where my problem comes to life, Ex. I create a work order for a client, add some items to it, and add the serial numbers. I save it, so I can do something else. After recalling the Work order, none of the coments (not even the S/N) are on it. I have check the Configuration \ Options on the manager and it seems to be ok. Any sugge...

Linking items GREATER THAN O on another worksheet in the same Work
I have a workbook that has about four worksheets … I want to create a list of items that will automatically be included on worksheet tab 4 from Worksheet tab 1 if the quantity for the item listed on the first worksheet has been changed from 0 to any other number (i.e. 1 or 10 etc). I have a list of equipment with pricing on worksheet tab 1 and the list is long. Many of the items will have quantities of zero and will not increase as they will not be selected for the project being created. We have additional columns for cost, extended cost, labor hours etc. If the quantity changes for a...

Calculate the total overlapping time of multiple tasks, excluding non-working times
I am developing a tracking calculator for an overall process. Within the overall process, there are 3 steps which are completed. These steps can be completed independently from one another, but can also (sometimes) overlap. I am trying to determine the total time for the overall process (from beginning to end), without counting the duplicated times where the steps are running parallel to one another, or times when some steps may be completed and are waiting for another to start. I have outlined the basic design of the worksheet below, with times in mm/dd/yyyy hh:mm format. S...

Links don't work in mail
Hello What would cause outlook (and outlook express) to not allow the links in my emails to work? They open a browser window, but nothing ever gets loaded. If this were happening only for 1 link, I'd say it was the url, but this happens with text links, button links etc. I have to "view source" for the button links, copy the url and paste it into my browser -- and that works fine. Email links seem to work. Any suggestions? Thank you Terry V Hold curser over link, press shift key, now you can click on link. "Terry V" wrote: > Hello > What would cause ou...

Rules Work Sporadically
I use an email classification tool (POPfile . . . getpopfile.org) that marks each email header using X-Text-Classification. I then set up rules in Outlook to recognize the header text and move the email to the proper folder. Here is the problem: sometimes Outlook places the email into the correct folder and sometimes it just lets the email pass through into the default folder even though the header reflects the proper X-Text-Classification. Does anyone have any idea why this rule would only work sporadically? Thanks. ...

Is GP right for an ISP?
We are a rapidly growing service provider. We’ve used a variety of billing programs, but nothing we’ve tried so far seems to offer the monthly reoccurring billing we need for our clients, and the ability to keep up with Inventory. We do T1s, and almost every customer we have ends up with a router, and a number of VoIP Phones. We have to keep up with a large number of hardware items, most with a unique MAC address and serial number for warranty and provisioning. GP seems to be able to handle our inventory requirements, but can it generate monthly invoices for services, and keep up with ...

Some rules don't work
Outlook 2007, XP Many of my rules have stopped working. Not all, but many, if not most. I even tried to delete some of the non-working rules and re-write them. But when I run them with messages already in my inbox, they don't work. I frequently copy my outlook.pst file for use on a laptop when travelling. It seems that some--but not all--stopped working at the time of such a transition. Of course, that does not explain why some won't work right after I make them. Many of the rules are what to do with emails I send and receive from certain people. Any suggest...

CMemFile not working in VC++ 6.0 RELEASE mode
I am using VC++ 6.0 and have a multi-threaded application (exe & multiple DLLs) which seem to be having a CMemFile object getting clobbered when running in release mode. It does not happen in debug mode. When running in the debugger, the calling thread that builds the memory file reports: GetPosition = 0 GetLength = 228 ptr to memfile = aa2238 the method GetTextLineNOF is passed a ptr to CMemFile and reports: GetPosition = 0 GetLength = 228 ptr to memfile = aa2238 Which agrees as expected. ==== However when running in RELEASE mode: the calling thread that builds the memory file rep...

Send/receive quit working
I have used Outlook 2002 without a problem for 6 weeks on a new Dell running home xp with the Mcafee security system including firewall. Microsoft articles suggest that outlook and Mcafee firewall are not compatible (worked for 6 weeks?) and the solution is to uninstall the Mcafee securities. Is there a way to run Mcafee with Outlook 2002? Is this just the firewall or also the anti-virus? If McAfee version 7, you will need to visit the McAfee forums for a fix. -- Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. After searching google.group...

Can a formula work on another cells formula?
I'm trying to get an offset function to work based on the target o another cells formula not on the cell itself and it's not working. Is there a way to tell a formula to act on the target cell and no simply on the cell? This is very hard to explain but it's really not that complicated. Wayn -- whagopia ----------------------------------------------------------------------- whagopian's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1608 View this thread: http://www.excelforum.com/showthread.php?threadid=27539 Hi really not sure what you're try...