473,738 Members | 7,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

turn quotes into " and apostrophes into '


Hi,

I'm looking for a javascript function that will convert input such as this:

<CLUB Code="

into this:

&lt;CLUB Code=&quot;
First, I thought the "escape" function would do it, but that does
something different.

The reason I want such a function is that we're using msxml's
xmlhttprequest to send xml , and for some reason the stuff inside the
soap envelope neds to be quoted as above.

Do I need to write this function myself (I'll probably use "regular
expressions" if I write it myself) or is there an existing function I
can call ?

Thanks. er*******@rcn.c om 4/12/04

Jul 23 '05 #1
2 20529
Eric Osman wrote:
I'm looking for a javascript function that will convert input such as
this:

<CLUB Code="

into this:

&lt;CLUB Code=&quot;

<snip>

An example of such a function can be found at:-

<URL: http://www.crockford.com/javascript/remedial.html >

Richard.
Jul 23 '05 #2


Richard Cornford wrote:
Eric Osman wrote:
I'm looking for a javascript function that will convert input such as
this:

<CLUB Code="

into this:

&lt;CLUB Code=&quot;


<snip>

An example of such a function can be found at:-

<URL: http://www.crockford.com/javascript/remedial.html >

Richard.

THanks Richard,

The routines I wrote look like this:

//+-------------------------------------------------------------
//| quoteXml puts appropriate quoting around various elements so
//| that was interpretable xml (or html) code will now be
//| displayable.
//| A new string is returned.
//+-------------------------------------------------------------
function quoteXml (xmlStr) {
var result = new EditableString( xmlStr);
result = result.replaceA ll("<", "&lt;");
result = result.replaceA ll(">", "&gt;");
result = result.replaceA ll("\"", "&quot;");
result = result.replaceA ll("'", "&apos;");
return result.data;
}

//+-------------------------------------------------------------
//| unquoteXml removes the quote marks, which is useful when
//| the returned stuff wants to be parsed as xml.
//+-------------------------------------------------------------
function unquoteXml (xmlStr) {
var result = new EditableString( xmlStr);
result = result.replaceA ll("&lt;", "<");
result = result.replaceA ll("&gt;", ">");
result = result.replaceA ll("&quot;", "\"");
result = result.replaceA ll("&apos;", "'");
return result.data;
}

Of course, to use them, you need my EditableString object definition too:

//+-------------------------------------------------------------
//| Object type editableString is a string that can be edited with
//| a number of useful methods contained below.
//+-------------------------------------------------------------
function EditableString( str) {
this.data = str;
}

//+-------------------------------------------------------------
//| replaceAll replaces all source strings with destination strings,
//| returning a new EditableString containing the result.
//+-------------------------------------------------------------
EditableString. prototype.repla ceAll = function (srcStr, dstStr) {
this.pat = new RegExp(srcStr," g");
var newStr = this.data.repla ce (this.pat, dstStr);
return new EditableString( newStr);
}
p.s. I often use an html "<textarea> " in which to display html that I
want to display for the person to see, so they angle brackets and
tags can all be seen.

However, I discovered that this is fine until you try to display
something like "&guot;" in a textarea. When you attempt that,
the browser (well, ie6 anyway) changes it back into a quote mark!

So, in order to make sure "&quot;" gets properly displayed, I
ended up having to change the ampersand to "&amp;" , so for
example, if var requestBody has some stuff in it that I wasnt to
display in a textarea, and that stuff might have "&quot;" in it,
I further quote it like this:

new EditableString( requestBody).re placeAll("&","& amp;").data)

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1991
by: C. Titus Brown | last post by:
Hi all, while playing with PBP/mechanize/ClientForm, I ran into a problem with the way htmllib.HTMLParser was handling encoded tag attributes. Specifically, the following HTML was not being handled correctly: <option value="Small (6&quot;)">Small (6)</option> The 'value' attr was being given the escaped value, not the
12
9472
by: Sammy | last post by:
Hi, my mind is going crazy. I have tried everything I can think of to no avail. I have tried Disable Output Escaping. I tried to think of a way of enclosing the attribute data in a CDATA element. That did not parse. Here is my question: How can I get attribute values to not get converted from &apos; to '
2
3024
by: Joe Gass | last post by:
I have an xml doc <sections> <section> <title>entry image</title> </section> <section> <title>22'2</title> </section> </sections>
4
14801
by: barney | last post by:
Hello, I' m using .NET System.Xml.XmlDOcument. When I do the following: XmlDocument xml = new XmlDocument(); xml.Load("blah"); .... xml.Save("blub"); I've got the problem that the following expression: .... snip ...
2
1546
by: Johnny Ljunggren | last post by:
Hello all Just noticed that a testprogram I've made creates a non-conforming XML file. Here's the code (C#) and output: XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; using(XmlWriter writer = XmlWriter.Create("xmltest.xml",settings)) { // Write XML data.
2
1226
by: Zyronne | last post by:
Hello.. How do i modify my stored proc that contains ...FOR XML AUTO to generate an xml output that will return myValue's instead of myValue&apos;s? Is it possible? I am finding ways to solve my problem immidiately during the generation of xml in the stored proc rather than when the xml is already created. Thank you.
1
2383
by: srinivasreddypn | last post by:
Hi everybody, can anybody guide me how to display a special characters like &quot;, &apos; in xml file into HTML page. Any help would be greatly appreciated. Thanks, srinivasreddy
3
7918
by: katieh | last post by:
My website is made in flash. I have a dynamic image gallery within. How flash knows what to load into my gallery is it refers to my .xml document. Within flash, it displays the picture, and then in the desc_txt, that is the object that loads in the text description from the .xml file. For some reason when the .xml loads the descriptions in, it does not recognize punctuation correctly. I'm not that familiar with xml, and I hate to just leave out...
3
2409
by: LionelAndJen | last post by:
I have an XML file that has a free form comment field in which the data provider, very kindly, already uses "&quot;" when writing "doesn't", I have doesn&apos;t . it's PERFECT, because that xml is then fed to an XSLT sheet that transforms this text into a sql insert statement. UNFORTUNATELY, XSLT translates doesn&apos;t into doesn't in the output, which then destroys my sql statement. How do I tell my XSLT to leave well-enough alone ? I...
0
8788
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,...
1
9263
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
tracyyun
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...
0
8210
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6751
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
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
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.