Click to See Complete Forum and Search --> : XML and Javascript
I am new to xml and realize the constraints of using javascript within xml. However, I have tried two methods of imbedding the javascript in the xml page, and neither have worked for me.
I first used the CDATA version that looked like this:
<script type="text/javascript">
/* <![CDATA[ */
// <src="http://weatherreports.com/jscript.html?width=234&height=60&theme=lblue_no_search_box&location=Phoenix%2C%20AZ&units=f">
</script>
/* ]]> */
</script>
This didn't work, so I tried using a reference to an external file, which looked like this:
<script type="text/javascript" src="/weather.js"></script>
Neither have worked for me so far, and I'm stumped. Any help would be appreciated.
For reference, this is in regard to the home page of www.kristinewman.com.
Thanks in advance for any assistance.
Stephen Philbin
01-29-2009, 04:17 AM
That Javascript you're trying to use. It wouldn't be adding content to the page using document.write() by any chance, would it?
Not sure about that one specifically, but I've also been trying to use javascript on a couple forms for validation purposes, i.e. to be sure required fields are being filled in before hitting Submit. Those aren't working for me either, and I'm using the same processes as above.
Not sure if that helps any...
Thanks.
And, to answer your question more specifically, here's the exact javascript from the .js document:
<script type="text/javascript" language="javascript1.2" src="http://weatherreports.com/jscript.html?width=234&height=60&theme=lblue_no_search_box&location=Phoenix%2C%20AZ&units=f">
</script>
Charles
01-29-2009, 07:47 PM
Yes, that piece of script doesn't work with XHTML.
rpgfan3233
01-29-2009, 08:40 PM
Yes, that piece of script doesn't work with XHTML.
That's right. The proper way to do it is to use the DOM, appending the iframe as a child element of whatever element to which the iframe should belong. :p
Charles
01-30-2009, 10:38 AM
It's not likely, however, that we can change the script. Suggest changing to HTML. This is yet another case where XHTML is causing a problem while offering no benefit.
I'm not certain that the document.write can't be said to be a pert of the DOM. A lot of what came before the DOM is included as the second chapter in the DOM 1 spec and is often known as DOM 0. But the long and the short of it is that in XHTML document.write is forbidden because it can lead to not well formed documents.
rpgfan3233
01-30-2009, 03:19 PM
Simple answer:
If that bit of XML will be used, things like appendChild should be used rather than document.write because there is no write method available for the document object in XML, which means that browsers who properly parse XHTML as XML (unless it is served as text/html) won't know what to do with document.write. If you use HTML, you won't be able to insert that XML into the document directly and have it work like magic because XML and HTML are not the same, unlike XHTML, RSS, etc. being XML with a defined grammar.
Technical answer:
Document object in DOM Level 1 (http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#i-Document)
DOM Level 0 refers to a number of functionalities offered by browser vendors before the W3C created their DOM recommendations. DOM Level 1 Core defines an object model for all HTML and XML documents as well as all XHTML documents since XHTML is XML.
DOM Level 2 HTML (http://www.w3.org/TR/DOM-Level-2-HTML/) defines the write (http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-75233634) and writeln (http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-35318390) methods for the HTMLDocument (http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26809268) interface. The HTMLDocument interface in DOM Level 2 HTML inherits everything from the Document interface in DOM Level 2 Core and adds extra functionality specific to HTML documents. However, this is for HTML only rather than XML (and XHTML, SVG, MathML, . . .). As a result, you can't use document.write in XHTML simply because no such method is defined for XML.
I hope this helps a bit.