473,386 Members | 1,799 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,386 software developers and data experts.

Problem with XHTML parsers with embedded HTML (e.g. firefox et-al)

Hi.. I've got some code I wrote in PHP that will generate a new argument
string for the browser, but the xhtml parser in Firefox and Opera both
complain about my use of &var=value pairs.

Below is my code that generates the string :

function InvokeURL(url_to_forward_to)
{
try
{
var xfamElem = document.getElementById('xFamily');
var mainform = document.getElementById('mainform');
var new_url = url_to_forward_to + "&variable=" + xfamElem.value;

mainform.action = new_url;
mainform.submit();
}
catch(error)
{
alert("InvokeURL encountered an error :" + error.description);
}
}

This works fine with *many* browsers except the new ones.. With IE on
windows (IE6) and Opera, Firefox all complain, Safari and some older
browsers seem to work OK..

If I change the line with the new_url variable setting on it to use a
& instead, it passes the XHTML tests but no longer works at all.. When
using the & it still has that in the URL that shows in the address
bar and hence it seems to cause the script on the other end a lot of
problems as it is unable to properly parse the URL string.

Any ideas on how to portably get around this problem with embedded &
created URL's?

Many thanks in advance!

-- Rick
Jul 17 '05 #1
2 2084
Rick wrote:
Hi.. I've got some code I wrote in PHP that will generate a new argument
string for the browser, but the xhtml parser in Firefox and Opera both
complain about my use of &var=value pairs.

Below is my code that generates the string :

function InvokeURL(url_to_forward_to)
{
try
{
var xfamElem = document.getElementById('xFamily');
var mainform = document.getElementById('mainform');
var new_url = url_to_forward_to + "&variable=" + xfamElem.value;

mainform.action = new_url;
mainform.submit();
}
catch(error)
{
alert("InvokeURL encountered an error :" + error.description);
}
}


That's javascript. I'd ask in a javascript newsgroup.
Jul 17 '05 #2
It would be more appropriate to consult an (X)HTML group.
These issues have been discussed at length in the past, so
the clues are in the archive. I don't see how any of what
follows relates to PHP though.

Rick wrote:
the xhtml parser in Firefox and Opera both complain about my
use of &var=value pairs.
Rightly so. The content of SCRIPT in HTML is CDATA; in
XHTML, #PCDATA. So in XHTML script elements, entity
references are recognised. Ampersands that should be
treated literally must be escaped. XHTML1.0 sec. 4.8 says:

| In XHTML, the script and style elements are declared as
| having #PCDATA content. As a result, < and & will be
| treated as the start of markup, and entities such as &lt;
| and &amp; will be recognized as entity references by the
| XML processor to < and & respectively. Wrapping the
| content of the script or style element within a CDATA
| marked section avoids the expansion of these entities.

http://www.w3.org/TR/xhtml1/#h-4.8

But in HTML, even though SCRIPTs have CDATA content, entity
references are not recognised; '&' is never the start of an
entity reference. HTML4.01 sec. 6.2 says:

| Although the STYLE and SCRIPT elements use CDATA for their
| data model, for these elements, CDATA must be handled
| differently by user agents. Markup and entities must be
| treated as raw text and passed to the application as is.

http://www.w3.org/TR/html4/types.html#h-6.2
&variable
In XHTML the ampersand must be escaped.
This works fine with *many* browsers except the new ones.
Tag soup slurpers might give it the impression of working,
but it's wrong.
If I change the line with the new_url variable setting on it to use a
&amp; instead,
Then it becomes valid XHTML.
it passes the XHTML tests but no longer works at all.
Because most browsers don't grok XHTML.
Any ideas on how to portably get around this problem with embedded &
created URL's?


In increasing order of preference:

1. Wrap the script's content in a CDATA section (XML1.0
sec. 2.7) and don't encode the ampersands.

2. Stop using inline scripts; move them to a separate
file.

3. Stop sending XHTML to browsers which don't support it.
You might choose to use content negotiation to send XHTML
to browsers which do support it and HTML to ones which
don't. Why bother?

--
Jock
Jul 17 '05 #3

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

Similar topics

2
by: Joe Price | last post by:
Hi chaps I've got an XML file, within that file i've embedded html code using the <!]> tag I'm displaying that xml file through a browser using an xsl style sheet. However it is displaying...
6
by: Moist | last post by:
Hi, I have an embedded HTML object as follows (ignore the code tag): <code> <object id="page" data="table.html" type="text/html" .... > </code> I look for the Javascript code (placed in...
2
by: Rick | last post by:
Hi.. I've got some code I wrote in PHP that will generate an HTML page with embedded javascript which in turn creates a new argument string for the browser, but the xhtml parser in Firefox and...
1
by: NancyASAP | last post by:
I have a label on my ASP.NET form. It has a cssclass that includes a background color. I am dynamically putting text in this label. The text contains some embedded html (I want to display part...
1
by: Bob Marley | last post by:
would anyone please tell me why this code works in 4.X, 5.0.X and not in 5.1? <?php function myfunction(){ *** php code *** ?> <a href="bla.bla">bla</a> <?
5
by: iegeek | last post by:
Hi all, I know this is a well-worn topic, but in viewing multiple posts and articles, I still can't find a satisfactory answer. I have embedded html in an xml file (element data, not attributes)...
4
by: mikeyeli | last post by:
Good day people! ive been searching all over the net for this, i think my problem is that i cant formulate the question the right way. how to have embedded html content inside a webform. html...
0
by: John Krukoff | last post by:
-----Original Message----- One method which wouldn't require much python code, would be to run the XHTML through a simple identity XSL tranform with the output method set to HTML. It would...
0
by: M.-A. Lemburg | last post by:
On 2008-04-24 19:16, John Krukoff wrote: You could filter the XHTML through mxTidy and set the hide_endtags to 1: http://www.egenix.com/products/python/mxExperimental/mxTidy/ -- Marc-Andre...
6
by: Guy Macon | last post by:
cwdjrxyz wrote: HTML 5 has solved the above probem. See the following web page: HTML 5, one vocabulary, two serializations http://www.w3.org/QA/2008/01/html5-is-html-and-xml.html
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.