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 "value". Is there a function that does that? If not, what
other characters do I need to replace?
-Oleg.
Martin Honnen wrote:
Ol*********@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/