Encode(quote) attribute value

Hi there,

I need to encode the value of an XML attribute, e.g.

             string myXml = "<element myAttr=\"" +
encodeURIComponent("my \"value") + "\"" ....";

Is there an equivalent of encodeURIComponent() javascript function as
part of the framework (1.1 or 2.0) which will encode special
characters, e.g. double quotes?

Thanks,
-Oleg.

0
10/19/2006 5:37:41 PM
dotnet.xml 7266 articles. 0 followers. Follow

5 Replies
1048 Views

Similar Articles

[PageSpeed] 13

For .NET languages, include the namespace System.Web.HttpServerUtility
and call the HtmlEncode method of the Server object.  The results are
equivalent to the javascript escape() method.

ie:

for VB.NET, where re

Imports System.Web.HttpServerUtility 'javascript escape/unescape
equivalency

encodedText  =  Server.HtmlEncode(unencodedText) 

Andy

0
anedza (69)
10/19/2006 6:26:03 PM
Andy wrote:
> For .NET languages, include the namespace System.Web.HttpServerUtility
> and call the HtmlEncode method of the Server object.  The results are
> equivalent to the javascript escape() method.

Where did you get that idea? HtmlEncode and JavaScript escape are 
different in the results they deliver. For instance HtmlEncode escapes 
'<' as '&lt;' while escape escapes '<' as '%3C'.

And the original poster asked about encodeURIComponent and not escape.

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1777)
10/20/2006 1:20:00 PM
Oleg.Ogurok@gmail.com wrote:

> I need to encode the value of an XML attribute, e.g.
> 
>              string myXml = "<element myAttr=\"" +
> encodeURIComponent("my \"value") + "\"" ....";
> 
> Is there an equivalent of encodeURIComponent() javascript function as
> part of the framework (1.1 or 2.0) which will encode special
> characters, e.g. double quotes?

JScript.NET is part of the .NET framework so one solution with .NET is 
to reference the JScript.NET dll for the global object and use its 
encodeURIComponent method.

But .NET independent of JScript.NET in its API has methods to encode 
URLs, see the UrlEncode method in the HttpUtility class
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebHttpUtilityClassUrlEncodeTopic.asp>



-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1777)
10/20/2006 1:37:51 PM
Actually, I'm not looking for encodeURIComponent() per se. I'm looking
for a function that will properly escape an XML attribute value in
cases when I'm creating XML document manually, i.e. by concatenating
strings rather than using XmlDocument/XmlAttribute/etc classes.

In this example I provided, the value of the attribute has a double
quote character ("), e.g. "my "value", so it needs to be replaced with
"my &quot;value". Is there a function that does that? If not, what
other characters do I need to replace?

-Oleg.

Martin Honnen wrote:
> Oleg.Ogurok@gmail.com wrote:
>
> > I need to encode the value of an XML attribute, e.g.
> >
> >              string myXml = "<element myAttr=\"" +
> > encodeURIComponent("my \"value") + "\"" ....";
> >
> > Is there an equivalent of encodeURIComponent() javascript function as
> > part of the framework (1.1 or 2.0) which will encode special
> > characters, e.g. double quotes?
>
> JScript.NET is part of the .NET framework so one solution with .NET is
> to reference the JScript.NET dll for the global object and use its
> encodeURIComponent method.
>
> But .NET independent of JScript.NET in its API has methods to encode
> URLs, see the UrlEncode method in the HttpUtility class
> <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebHttpUtilityClassUrlEncodeTopic.asp>
>
>
> 
> -- 
> 
> 	Martin Honnen --- MVP XML
> 	http://JavaScript.FAQTs.com/

0
10/20/2006 3:31:55 PM
Oleg.Ogurok@gmail.com wrote:

> In this example I provided, the value of the attribute has a double
> quote character ("), e.g. "my "value", so it needs to be replaced with
> "my &quot;value". Is there a function that does that? If not, what
> other characters do I need to replace?

If you use XmlTextWriter (respective XmlWriter in .NET 2.0) to construct 
your XML then it does all escaping automatically for you e.g. in the 
WriteAttributeString call e.g. C#

   xmlWriter.WriteStartElement("root");
   xmlWriter.WriteAttributeString("attribute", @"Kibo is ""GOD""");

will yield the XML markup

   <root attribute="Kibo is &quot;GOD&quot;" />

So all you need to use is the proper XML APIs (e.g. XmlWriter) and 
escaping to meet XML well-formedness rules is done automatically.


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1777)
10/20/2006 3:50:29 PM
Reply:

Similar Artilces:

Using "offset" functionality in graphs. HOW?
I have created worksheets which utilize "offset" functionality, so that on a weekly basis I only have to change a single value and multiple tables I have set up automatically change to roll with changes in dates. Now I have set up graphs to reflect the data, but find myself updating ranges inside the graphs weekly. I would like to use the same type of functionality so that the single field update I do ALSO changes the graph ranges. I tried to use the "offset" functionality in the source date - value section of the graph, but received an error message that the func...

Getting the "name=" (bit, picklist) value that is returned from SOAP
Hi all, I am getting several fields via a Web service request in javascript in an OnChange event to poulate other field on a case. One of those fields is a bit, and one is a picklist. Those nodes in the response come back with <attribute="new_active" name="true">1</attribute> for the bit field and <attribute="status" name="On Hold">3</attribute> How can I read the name value? I've tried selectSingleNode("//status").name with no luck. Thanks! I am doing a similar process, using a SOAP response message. I ge...

How do I access a document after "access denied" message?
I am running Windows 7 Home and Office 2007. I am signed in as the Administrator. I am being denied access to Word documents that I created. I have gone in to "Properties" for the documents and see access granted to the administrator. But, I can't get in. How do I change this? ...

which table Picklist integer value stored?
Hi there, Which database table pick list interger values stored? thanks Kyaw this query will list all the pick list integervalues and attribute name select AttributeName,AttributeValue,Value from StringMap // for account WHERE (StringMap.ObjectTypeCode=1) //for contact WHERE (StringMap.ObjectTypeCode=2) attributename will tell u about the name of the picklist attribute value is the intigers and values are what u can see on the form i think this will help u ...

Taking one value sheet 1 and apply to sheet 2
Hello all, I have a workbook with 5 sheets. I do not know how to take the valu from sheet 5 cell b26 and use that value to a formula to sheet 1 cel g19. Can someone help me out? : -- join_the_ban ----------------------------------------------------------------------- join_the_band's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=3521 View this thread: http://www.excelforum.com/showthread.php?threadid=54975 Try a formula like =Sheet5!B26 "join_the_band" <join_the_band.2926qb_1149728701.4689@excelforum-nospam.com> wrote in message news:joi...

Pre-configuring Pivot table "views"
I need to create several different pivot tables from the same set of data. However, I need to keep switching between the different tables and it quickly becomes a cumbersome process selecting different rows, columns, and sigma values, each time I want to look at a certain pivot table. I know I can create different pivot tables and put them in seperate sheets instead of dynamically updating the same pivot table to get the data I want. I was wondering if there was a way I could preconfigure all these tables and simply "select" one of the "views" so I wouldn't ...

"Can't Create Backup FIle. Save [filename] Without Backp?
I get the following message every so often when running Excel 2003 under Win XP: "Can't create backup file. Save [finename] without backup?" I respond: "OK" "Your changes could not be saved to [filename] because of a sharing violation. Try saving to a different file." I respond: "OK". It presents me with the standard window allowing me to enter a new filename, which I do, then press OK. Then I get: "Do you want to save the changes you made to [fileename]? I respond: "Yes" "Document not saved." This is VERY annoying. I am t...

WMP 11 will not "add to library"
I was out one day when the power went out. My computer obviously shut down, and as a result WMP shut down improperly. This hasn't been the first time, and whenever it does, I just start up my computer again, log in, and WMP 11 is working just fine. There has also been some instances when the library has been corrupted, and I've just re-added my files to the library again. However, this time it's different apparently; WMP 11 refuses to add ANYTHING to it's library, and whenever I choose a folder for it to monitor, it does absolutely nothing, as opposed to adding ...

Linking Outlook fields from the "Contact Folder" to a custom form in Outlook...
Using Exchange Server 2003/Outlook 2003, we have created a custom Help Desk form in Outlook. We would like the ability to link specific fields from the Contacts Folder (Example B), in a drop-down list box if possible. We are far from knowing that something like this is even possible. Would appreciate *any* suggestions. Thank you. ...

Showing "Meeting point" of lines in Chart
Hi, I am trying to create a chart (with a data from a table). I'm using excel 2003. I manage to do it pretty well, I'm just facing one problem: I have 2 lines which are crossing eachother in a curtain point. Is there an option to show this exact point on the chart? (meaning, with the exact X and Y location) I couldn't find such option in the chart properties and settings... Many thanks! JJ. -- jinjon ------------------------------------------------------------------------ jinjon's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=28903 View this thr...

Home Server Attribute: msExchHomeServerName
This is very odd, I have migrated over a 1000 users to Exchange 2003 but still have a few hundred to go on my legacy Exchange 5.5 systems. Everything works well, but there is something wrong that I can't figure out. When I create a new user account & mailbox via Active Directory Users & Computers (mailbox on the Exchange 2003 system, NT account in AD), the new AD object gets replicated to the Directory Service on the Exchange 5.5 systems..however, the Home Server attribute is set to None and at that point, none of my Exchange 5.5 users can email them. The fix is simple, ...

Moving Macros from Personal.xls to "This Workbook"
I created macros and stored them in Personal.xls and now want to move them to "This Workbook". How do I do that? Tina What are these macros for? The ThisWorkbook module exists in every Workbook (even the Personal.xls), and is there to trap events (such as the workbook being opened) so that specific code can be run. Do you have a need to do this? If you go into the Visual Basic Editor (Alt+F11) you should see the code modules in your Personal.xls. You can simply select the text and copy and paste into a code module in another workbook (the macros are stored as text data), so i...

"Don't have appropriate permission" to send/receive
Let me add my complaint to the chorus of others I've seen on this newsgroup. Frequent readers will recall the symptoms: On Win XP Home, I can send/receive email using Outlook just fine, but my wife and kids cannot. They can send/receive test emails from Outlook's Tools->Email Accounts... (o) View or Change Account ... [Test Account Settings], but they get "You don't have appropriate permission to perform this operation" when they click on the Send/Receive button. We all have "computer administrator" privileges. I tried creating a new profile, as Mark Joh...

[ANN] "Dbl-Click Won't Open..." Issues
This message has been cross-posted to the Macintosh Word, PowerPoint, Excel & Office groups. The problem some of you have been experiencing whereby a file received via email refuses to open when double-clicked has been traced to email and/or web browser software mishandling the file sometime during its life cycle. Apparently certain programs of those types modify a key identifier in MS Office files which the 2008 apps require in order to be activated & open a file when it's double-clicked . Although identity of the software hasn't been identified, MacBU is working with the de...

Dynamic Value in Workflows
Hello, I am creating some workflows and I want to set a value in an Account Entity based on a value in the Opportunity Entity. I believe I should be able to use the Dynamic value wizard within Workflow manager - i.e. select Account and the filed and select = and then go to Dynamic Value and select Opportunity and the field that I want the value to inherit on change of status. However when I do this I can only select Account within the Dynamic Value picklist. Any ideas? Dynamic Values are only available to children of Parent entities. Since Accounts are at the top of the CRM food c...

Hiding Returned Value of hlookup
Okay, this is a tough one... (At least for me) I'm using the hlookup formula to import the starting times and ending times of employees on a daily assignment sheet. I'm compiling all the times onto a weekly schedule where each individual's hours for the week are added up. Now, I've done all this, but I get #NA when a particular employee is not on a certain day. I'm currently using IF and ISERROR to convert the #NA to "0", which allows the sheet to properly add up the hours being used by each employee. Now, I need to be able to hide the zeros so I can pri...

Counting Different Values
Well here we go, i have coloum B which has the name of the person and column F has the number now i want to have a summary page which has : Name & Number from the other page counted up. For Example: Robert Smith 10 Robert Smith XX Jim Smith 10 Jim Cox 10 Jim Cox XX Jim Cox 10 and on the summary page it has: Robert Smith - 10 Total: 1 Robert Smith - XX Total: 1 J...

AutoFill Changing Wrong Value
I'm trying to create an analysis sheet that gathers data from 100 worksheets within the same workbook. I want the same cell reference in each sheet, but to change the sheet number in each cell. The worksheets are named 1 - 100 Here is the formula: ='1'!B3:E3 It changes the cell references only, not the worksheets. I've changed the formula to keep the cell references: ='1'!$B$3:$E$3 I now need the formula to increment the sheet number each time, PLEASE!!! Thanks, Lisa Presumably you want to sum data from that range? Try this: =3DSUM(INDIR...

Help with counting values that have different endings
Hi guys, i just joined SQLMONSTER and was wondering if you guys can help me with this problem... I have 10 columns and 8,000,000 rows which have stock ticker names and exchange tickers-like the following: [Column A] AQR.L GDY.LS NBAE.LS (blank) 0023CA.S FOR.L AQR.KZ ... ... How do I find the number of unique ticker names in my database and disregard the .L, .LS, .S, .L, .KZ endings (because I am looking for the unique tickers, not the exchange). I.E., I want the values counted to be only AQR, GDY, NBAE, 0023CA, FOR or 5 values (I don't want AQR to be counted twice becau...

What does "Your Microsoft Exchange Server is Unavailable" mean?
Cannot use Outlook 2003, I get an error message as above with 3 choices. Retry, Work Offline or cancel. If i select work Offline, I get another message that says "unable to open your default e-mail folders. Your profile is not configured. The choices are "okay." If I click okay, the program closes. I have uninstalled and installed again 3 time. Still does the same thing. How do I fix this? Have never used Outlook before - cannot open it. Juanita wrote: > Cannot use Outlook 2003, I get an error message as above with 3 > choices. Retry, Work Offline or cancel. If i se...

how we can retrieve the value of edit control of combobox.
hi guys, how r u, can you please tell me how we can retrieve the value of edit control of combo box. actually i want to allow the user to input data in the combobox and then save this data in the database. i don't want to select already exist data in list box of combobox. please help me. raghunandan_1081@yahoo.com wrote: > hi guys, how r u, can you please tell me how we can retrieve the value > of edit control of combo box. actually i want to allow the user to > input data in the combobox and then save this data in the database. i > don't want to select already exist da...

"Find and Replace" in Sheet names
Is there a way (with code perhaps) to search and replace sheet names? For example, I have 20 sheet names with "Direct (2)" in the name, and I'ld like to replace teh "Direct (2)" in the sheet name to "Net" in each instance. Thanks, Jim One way: Public Sub Direct2ToNet() Const sRepl As String = "Direct (2)" Dim ws As Worksheet Dim nPos On Error Resume Next For Each ws In ActiveWorkbook.Worksheets With ws If .Name Like "*" & sRepl & "*" Then _ ...

How set totals of various cells with per colour fill value?
I have a sheet containing values as follows. April May June company 1 43 company 2 5 company 3 17 The cell values are also coured to indice a status. Somewhere beside the table I want to mention the totals of the cells, per status (so per colour). How to perform the latter? Thank you. Bart Excell 2003 See http://www.xldynamic.com/source/xld.ColourCounter.html for a working solution -- HTH Bob Phillips (remove xxx from email address if mailing direct) "AA Arens" <bartvandongen@gmail.com> wrote in mes...

MTA "congestion"
EXCH5.5SP5... I have two servers, one is a bridgehead and another has all my mailboxes. When I backup the primary server, I have noticed that it goes MUCH quicker when I do not have ANTIVIRUS running. So, I shut down the AV. Since my AV is shutdown, I turn off theMTA between the Bridgehead and primrary server. I had thought this would be OK. and have run this way for a few years, but within the past couple of months folks have reported that some of their email contacts report bounced messages. Investingation reveals that these bounced messages are due to congestion... Reading MS KB 230497. I...

Mail downloading as "opened"
I have Outlook 2002. I just set up a user account on a new computer and the mail has rules sending it to the individual folders. When I download the mail it goes to the specified folders, but doesn't remain unopened, so I don't know when there is new mail. All my mail is being "opened" when downloading. How do I correct this? Thanks! __________________ Stacey ------------------------------------------------ ~~ Message posted from http://www.OutlookForum.com/ ~~ View and post usenet messages directly from http://www.OutlookForum.com/ ...