473,407 Members | 2,676 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,407 software developers and data experts.

Parsing iframe's XML in JavaScript (AJAX trick?)

Since XMLHTTP Request does not support loading of XML from other
servers, I decided to use a trick:
load XML into hidden iframe and then get that XML with JavaScript to
parse.
But, is this a good idea? I am stuck. How do I get XML loaded in the
iframe and pass it on to JS function for parsing?
Thank you.

Oct 3 '06 #1
11 8555


vu******@gmail.com wrote:
Since XMLHTTP Request does not support loading of XML from other
servers, I decided to use a trick:
load XML into hidden iframe and then get that XML with JavaScript to
parse.
But, is this a good idea?
You can load the XML in the (i)frame but script can't access the DOM
then as the same origin policy applies as well to that approach so you
get access or permission denied if the iframe contains a document from a
different origin.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 3 '06 #2
How do Google RSS feed work? They must have some workaround, dont they?

Either way I found this to be a workaround so far, but I test it by
now:

example of how to use an IFRAME to parse an HTML document into a DOM:
http://youngpup.net/userscripts/html...xample.user.js

Oct 3 '06 #3


vu******@gmail.com wrote:

Either way I found this to be a workaround so far, but I test it by
now:

example of how to use an IFRAME to parse an HTML document into a DOM:
http://youngpup.net/userscripts/html...xample.user.js
That is a user script or Greasemonkey script you have to install first.
If the user installs such a script then it is not subjected to the same
origin policy that applies to scripts in documents (e.g HTML or SVG
documents) loaded in a browser window.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 3 '06 #4
Hm... are you trying to say, there is no way for me to parse iframe's
loaded XML file using JavaScript XML parser?
Thank you very much.

Oct 3 '06 #5
vu******@gmail.com wrote:
How do Google RSS feed work? They must have some workaround, dont
they?
They have a server-side app that connects to the server and grabs the
output.
Your browser is still requesting a url from google.com, but passing the
actual url to retrieve via the "proxy".
So, there is no problems with same origin policies.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Oct 3 '06 #6
I still believe this may work:

var iframe = document.getElementById("myiframe");
var obj = iframe.contentDocument.open("text/xml");

obj - is an HTML object of iframe document. If I know how to make it an
XML object, I am done with my problem.
Any thoughts and ideas are VERY welcome.
Thank you.

Oct 3 '06 #7
VK

vu******@gmail.com wrote:
I still believe this may work:

var iframe = document.getElementById("myiframe");
var obj = iframe.contentDocument.open("text/xml");

obj - is an HTML object of iframe document. If I know how to make it an
XML object, I am done with my problem.
Any thoughts and ideas are VERY welcome.
You are still missing the picture: the problem is not in using iframe
for XML document. The problem is that iframe having a content (any
content) from another domain is not accessible from the main document.
Not because there are not methods to do it: but because these methods
are blocked for any kind of cross-domain communication.

With the same luck you could simply override the <scriptelement (IE
only though):

<script type="text/xml" src="data.xml"></script>

<script type="text/jscript">
var DynamicSource;
var DataIsland;

function demo() {
DynamicSource = document.scripts[0];
DataIsland = DynamicSource.XMLDocument;
window.alert(DataIsland.firstChild.nextSibling.nod eName);
}

window.onload = demo;
</script>

Works like a charm on the same domain, "Access denied" else.

Oct 3 '06 #8
So does everyone say I cannot do anything but using a server side code
to get, parse and return XML?
Please, confirm...

Oct 3 '06 #9
VK

vu******@gmail.com wrote:
So does everyone say I cannot do anything but using a server side code
to get, parse and return XML?
Please, confirm...
"I cannot do anything but using a server side code to get, parse and
return XML from a source located in another domain".

In this form that's correct, confirmed.

Oct 3 '06 #10
VK
Correction:

"I cannot do anything but using a server side code to get, parse and
return XML from a source located in another domain under standard
security restriction".

That is the main reason of RSS feeds overuse and misuse: people are
trying to escape this idioticy at least on some most modern browsers.

It is a pure idioticy because it adds nothing to the existing security.
Instead it forces thousands of people to act like hackers on their own
servers (using mod_rewrite, content grabbers and other tricks). It also
forces thousand of thousands of developers to start the career from
thinking of *hacking* things rather than of *using* them. That is maybe
the worst impact of it.

Overall the "issue" is acknowledged by all key players and it goes to
an implementation of data binding's approach with server side
"permissions file". But gosh are they slow on doing...

Oct 3 '06 #11
vu******@gmail.com wrote:
So does everyone say I cannot do anything but using a server side code
to get, parse and return XML?
If you're writing a page for other people to use, then that is correct.
You cannot access cross-domain information by browser alone.

If you're writing a page for YOU ALONE to use, then create an IE HTA
application. For example, save the following into a file called
"cross_domain.hta" and run it, then click the button. You have access
to the data because it's an application running on your computer.
Rename it to "cross_domain.html" and it won't work.

<html>
<body>
<input type="button"
onclick="alert(XFRAME.document.body.innerText)"
value="Test"/>
<iframe id="XFRAME" width="100%" height="80%"
src="http://www.w3schools.com/xml/note.xml">
</iframe>
<body>
</html>

Kev

Oct 4 '06 #12

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

Similar topics

3
by: chopperuk | last post by:
Hi just a quick one, for a project I am completing, I need to bascially, have a form on a web site (where a user types in a question), this then, needs to question a chat bot (programE - ALICE), and...
1
by: JohnnieTech | last post by:
I am using some javascript/ajax to load content into a main div. The problem I am running into is that it will work in IE but not in FF. In FF I don't get any sort of load at all. I have a 1...
4
by: Smudly | last post by:
I am trying to write a simple Ajax application using SUSE 10.2, Apache, PHP and Javascript. I want to click on a table header and do some processing to update the table. i have a function...
1
by: satishr23 | last post by:
Hi, I am having some problems with handling cross domain requests in javascript/ajax and would really appreciate any help. My client has a javascript file which he includes in his HTML...
2
by: papillonhn | last post by:
hi everybody. I have a question: Doesn't Ajax for .net have xmlserializer class in javascript? It just have Sys.Serialization.JavaScriptSerializer library to use for Json. I need a...
2
by: ShadowLocke | last post by:
Im afraid I may already know the answer to this..But i would like to hear from any one with some experience. Is there any way at all, to prevent/detect if javascript was run from the address bar...
61
anfetienne
by: anfetienne | last post by:
could anyone tell me the mthod to use javascript/ajax to post to a sql database? or could someone point me to a tutorial?
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.