Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic XML from IFRAME 1

Status
Not open for further replies.

LFI

Programmer
Apr 27, 1999
1,996
US
Hi,

I am writing a JSP which hits a database table and draws an HTML table from the data.

When the table contains too many rows (let's say about 200 or greater), the drawing is slow.

In the interests of speeding things up, I am investigating other ways of building the table. For the sake of experimentation, I was thinking of trying some variation on XML and XML Islands.

What I have write now is an IFRAME within a page in which the XML is built via JSP.

In the outer page (parent), I want to gather that XML.

When I use an XML island in the SAME PAGE (i.e., no IFRAME) and source it to a static XML file, I can do a

Code:
var xmlObjects = document.getElementsByTagName("XML");

...to get the island.

Using the IFRAME approach, I was hoping to do something like:

Code:
var xmlObjects = document.frames["xmlFrame"].document.getElementsByTageName("XML");

...but this hasn't worked. My xmlObjects array length is 0 after doing this. I have tried other things, but it's just shooting in the dark.

Any ideas on how to grab this dynamically built XML?

I am prepared for this method to NOT be any faster than what I've already tried, but for academic purposes, I figured I'd go through with testing it anyway.

Thanks for your time!

--Dave
 
Thanks simon. Yes, I tried something just like that. The problem is that the when you examine the "HTML" of an XML file, it's all crazy. It looks like there's an <XML> tag, but in reality (when searching for it with getElementsByTagName), it cannot be found. In the "HTML," it doesn't exist.

It's weird. I'd post some sample code you could look at if you'd like to see what I mean.

--Dave
 
is the iframe page served from another domain ??

there are security issues within browsers to stop access to
the client code of other sites' pages.

by all means post some code though.

 
It could be the parent window calls the XML island in the iframe before the iframe's is completely loaded. Best is the initiate the call from iframe to the top window.
 
Thanks for your replies. It's not a security thing or an order-of-events thing. Copy and paste the two files below and check this out. You can see the XML in the IFRAME, so you know it's there. Once you see the IFRAME contents, click the button in the parent frame. I have made the code lines bold which dictate what you see when you press that button. It's weird!

Here's the HTML for the 'parent' page:

Code:
<html>
<head>
<script>
function showXmlIsland()
{
 var xmlObjects = top.xmlFrame.document.getElementsByTagName("XML");
 [b]alert(top.xmlFrame.document.body.innerHTML);
 alert(xmlObjects.length);[/b]

 for(var i=0; i<xmlObjects.length; i++)
 {
  var surroundingTag = xmlObjects[i].getElementsByTagName("collectionName");
  var collectionTag = surroundingTag[0].getElementsByTagName("collectionItem"); 
  //only one root-style tag expected
  for(var k=0; k<collectionTag.length; k++)
  {
   var collectionAttributes = collectionTag[k].getElementsByTagName("*");
   for(var l=0; l<collectionAttributes.length; l++)
   {
    alert("xml id: "+xmlObjects[i].id+"\ncollection "+k+"\n"+collectionAttributes[l].tagName+": "+collectionAttributes[l].text);
   }//end for
  }//end for
 }//end for
}
</script>
</head>
<body>
<input type='button' value='show island' onclick='showXmlIsland()' />
<iframe name='xmlFrame' src="island2.xml" width='100%' height='20%'>
</iframe>
</body>
</html>

Here's the xml for 'island2.xml'

Code:
<xml id="island">
<collectionName>
 <collectionItem>
  <name>item 1</name>
  <description>My first item</description>
 </collectionItem>
 <collectionItem>
  <name>item 2</name>
  <description>My second item</description>
 </collectionItem>
</collectionName>
</xml>

Any more thoughts or insights are welcome! Thanks again.

--Dave
 
To be able to use XML island, you have to save your island2.xml as HTML. and the iframe should refer it as HTML. i.e. Then it should.

<iframe name='xmlFrame' src="island2.html" width='100%' height='20%'>
</iframe>
 
Yup, that does it. I had trouble seeing the forest because all the trees were in the way! :)

Star for you.

Thanks!

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top