473,323 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

problem with html entity in string


I want to substitute "\(" by "("

i have tried

content = content.replace(/\\\(/g, "(");

content = content.replace(/\\\(/g, unescape("%26") + "#40;");

content = content.replace(/\\\(/g, "\&" + "#40;");
In all three cases the resulting HTML is "("

How do i force "&" to be "&" instead "&"?

--
http://canonicalscience.org/en/misce...guidelines.txt
Jun 27 '08 #1
5 1658
On May 8, 1:44 pm, "Juan R." Gonzlez-lvarez wrote:
I want to substitute "\(" by "("

i have tried

content = content.replace(/\\\(/g, "(");

content = content.replace(/\\\(/g, unescape("%26") + "#40;");

content = content.replace(/\\\(/g, "\&" + "#40;");

In all three cases the resulting HTML is "("
The result of the javascript - replace - method is a javascript string
primitive, not HTML. If the input string is the backslash character
followed by the opening parenthesis character then the output string
is _never_ "(". So the odds are that either you have omitted
context that is significant to your problem of your problem is down-
stream of your use of the - replace - method (or possibly your input
strings are not what you think they are).
How do i force "&" to be "&" instead "&"?
There is nothing to force until the cause and effect relationship has
been identified, and it is not in the - replace - method calls. Try
posting a minimal text-case page that demonstrates the effects you
observe in isolation.
Jun 27 '08 #2
Henry wrote on Thu, 08 May 2008 06:38:38 -0700:
On May 8, 1:44 pm, "Juan R." González-Álvarez wrote:
>I want to substitute "\(" by "("

i have tried

content = content.replace(/\\\(/g, "(");

content = content.replace(/\\\(/g, unescape("%26") + "#40;");

content = content.replace(/\\\(/g, "\&" + "#40;");

In all three cases the resulting HTML is "("

The result of the javascript - replace - method is a javascript string
primitive, not HTML.
Exactly i want to substitute a string by other.
If the input string is the backslash character
followed by the opening parenthesis character then the output string is
_never_ "(".
But i got just that output in end page. Is then the problem in the
createTextNode method (see below)?
So the odds are that either you have omitted
context that is significant to your problem of your problem is down-
stream of your use of the - replace - method (or possibly your input
strings are not what you think they are).
E.g. the input string is "\(n\)"

and the result i got is "(n)"

but it would be "(n)"
>How do i force "&" to be "&" instead "&"?

There is nothing to force until the cause and effect relationship has
been identified, and it is not in the - replace - method calls. Try
posting a minimal text-case page that demonstrates the effects you
observe in isolation.
Ok, try with this to see the script in action

http://www.canonicalscience.org/en/r...canonical.html

The code is at

http://www.canonicalscience.org/en/codes/main.js

the part is at the end /* CANONML TO HTML */

--
http://canonicalscience.org/en/misce...guidelines.txt
Jun 27 '08 #3
"Juan R." González-Álvarez wrote on Thu, 08 May 2008 16:51:29 +0200:
Henry wrote on Thu, 08 May 2008 06:38:38 -0700:
>On May 8, 1:44 pm, "Juan R." González-Álvarez wrote:
>>I want to substitute "\(" by "("

i have tried

content = content.replace(/\\\(/g, "(");

content = content.replace(/\\\(/g, unescape("%26") + "#40;");

content = content.replace(/\\\(/g, "\&" + "#40;");

In all three cases the resulting HTML is "("

The result of the javascript - replace - method is a javascript string
primitive, not HTML.

Exactly i want to substitute a string by other.
>If the input string is the backslash character followed by the opening
parenthesis character then the output string is _never_ "(".

But i got just that output in end page. Is then the problem in the
createTextNode method (see below)?
Ok i think that Henry is right and the problem is not in replace but in
the posterior createTextNode method when it finds the "&" in the string
and escape like "&" when generating the HTML.

What would be more easy way to fix that?
--
http://canonicalscience.org/en/misce...guidelines.txt
Jun 27 '08 #4
Juan R. González-Álvarez wrote:
Ok i think that Henry is right and the problem is not in replace but in
the posterior createTextNode method when it finds the "&" in the string
and escape like "&" when generating the HTML.

What would be more easy way to fix that?
ISTM there is no problem but a misconception of yours that needs fixing.
The DOM2Core:Document::createTextNode() method that you presumably speak
of takes a DOMString value as argument, supported by a primitive string
value in ECMAScript implementations per the DOM 2 Core Specifications'
ECMAScript Binding section.

document.createTextNode("&")

is supposed to create a TextNode object[1] with the content

&

and return a reference to it which is represented in HTML by

&

among other entity references. Maybe you think that

<a href="http://foo.example/?bar=42&amp;baz=23">...</a>

would not be correct in which case you should read on SGML and HTML, and
validate your markup (you should do that anyway) because you were wrong then.

See also:

http://www.w3.org/TR/DOM-Level-2-Core/
http://www.w3.org/TR/html4/
http://validator.w3.org/
PointedEars
-----------
[1] "Foo object" is a short-hand term for "an object that implements the
Foo interface"
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Jun 27 '08 #5
"Juan R." González-Álvarez wrote on Thu, 08 May 2008 14:44:59 +0200:
I want to substitute "\(" by "("

i have tried

content = content.replace(/\\\(/g, "(");

content = content.replace(/\\\(/g, unescape("%26") + "#40;");

content = content.replace(/\\\(/g, "\&" + "#40;");
In all three cases the resulting HTML is "&amp;#40;"

How do i force "&" to be "&" instead "&amp;"?
Yes, the problem was on the CreateTextNode and not in the replace method.
I had simply adapted a previous code for CanonML 0.6 to CanonML 0.7 and
then introduced replace.

I have eliminated replace method introduced a next token variable and
modified the nested if to go over escaping backslashes. It is now
working. See

http://www.canonicalscience.org/en/r...canonical.html

Place your mouse over an equation and you can see original code.

Thanks Henry and Thomas.
--
http://canonicalscience.org/en/misce...guidelines.txt
Jun 27 '08 #6

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

Similar topics

6
by: Horst Gutmann | last post by:
Hi :-) I currently have quite a big problem with minidom and special chars (for example &uuml;) in HTML. Let's say I have following input file:...
5
by: Clifford W. Racz | last post by:
Has anyone solved the issue of translating lists in Word 2003 (WordML) into xHTML? I have been trying to get the nested table code for my XSLT to work for a while now, with no way to get the...
0
by: David W. Fenton | last post by:
Well, today I needed to process some data for upload to a web page and it needed higher ASCII characters encoded as HTML entities. So, I wrote a function to do the job, which works with a table...
3
by: dskillingstad | last post by:
I'd appreciate any help I can get. I'm not sure what I'm doing wrong, but.... I've searched these groups for some solutions but no luck. I have an unbound form (frmSearch), with several unbound...
3
by: Dale Strickland-Clark | last post by:
A colleague has asked me this and I don't know the answer. Can anyone here help with this? Thanks in advance. Here is his email: I am trying to parse an HTML document using the xml.dom.minidom...
6
by: Melissa | last post by:
Initially the form is loaded using ASP and HTML and the ü codes display the characters correctly. I have the values stored in a javascript array so that I can more easily and dynamically change...
7
by: petedawn | last post by:
hi guys, based on users button press i am passing the following to my javascript function, test('&eacute;'). and within my javascript i have this function test(x) which processes this input. ...
10
by: Aray | last post by:
<!ENTITY % testEntity "(test)"> <!ELEMENT testElement %testEntity;> Above is a valid DTD file. But it doesn't work when I try to put a charater '/' in to the Content of testEntity. like...
3
by: Henri | last post by:
Hi, How would one go about comparing 2 strings one of which may contain special entities (eg "cass" and "cassé")? I tried to find a way to take the second string and do a replace whenever such...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.