8 Replies - 2482 Views - Last Post: 29 July 2009 - 08:07 PM

#1 shriek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 26-June 09

How to close XmlDocument file?

Posted 14 July 2009 - 02:32 PM

This has been frustrating me for weeks now. In my code I have to open an xml file and close it again and open it again..this goes on....This is done to know the current filesize of my xml file and I am having problem with closing the xml document...
Is there even a way to do this?
Is This A Good Question/Topic? 0
  • +

Replies To: How to close XmlDocument file?

#2 forest51690  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 58
  • View blog
  • Posts: 340
  • Joined: 20-March 09

Re: How to close XmlDocument file?

Posted 14 July 2009 - 09:31 PM

AJAX doesn't close the file because it doesn't really have a file handle on it. Maybe the problem is that AJAX is caching the requested file, because that's what it does. The way to get around this is to append a random GET variable onto the end of the URI. So if your URI was like this: "xml/my_data.xml" then make it so the URI looks something like this: "xml/my_data.xml?rand23553=23769" where both of the numbers are random numbers. That will make sure you're loading the current version of the file with AJAX.
Was This Post Helpful? 0
  • +
  • -

#3 shriek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 26-June 09

Re: How to close XmlDocument file?

Posted 18 July 2009 - 12:52 PM

I tried and tried..but I can't seem to get it....do the browser load same xml file(pretending to be different) if a different variable with it's URI should be passed?
Was This Post Helpful? 0
  • +
  • -

#4 forest51690  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 58
  • View blog
  • Posts: 340
  • Joined: 20-March 09

Re: How to close XmlDocument file?

Posted 18 July 2009 - 08:53 PM

Yeah, once AJAX loads a page with a specific URI, it caches it and it won't load the same cached file even if the real file changes. What you need to do is to make Javascript generate the URI you are requesting with AJAX, like this:

var uri = "mydocument.xml?rand"+randomNumber()+"="randomNumber();

randomNumber is not an existing function, so you will have to create it.

And then load the document using AJAX with the generated random URI.
Was This Post Helpful? 0
  • +
  • -

#5 shriek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 26-June 09

Re: How to close XmlDocument file?

Posted 22 July 2009 - 06:19 PM

ok the thing you said worked!!!.. but what I'm really having problem is with something like this:-
<html>
<script type="text/javascript">
function myFun()
{
var firstSz = <?php echo filesize('news.xml')?>;
myFun2();
}
function myFun2()
{
var newSz = <?php clearstatcache(); echo filesize('news.xml')?>;
alert(newSz);
setTimeout(function(){myFun2();},5000);
}
</script>
<body onload="myFun()">
</html>
Was This Post Helpful? 0
  • +
  • -

#6 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: How to close XmlDocument file?

Posted 23 July 2009 - 04:02 AM

close php code in quotes
<html>
<script type="text/javascript">
function myFun()
{
var firstSz = "<?php echo filesize('news.xml')?>";
myFun2();
}
function myFun2()
{
var newSz = "<?php clearstatcache(); echo filesize('news.xml')?>";
alert(newSz);
setTimeout(function(){myFun2();},5000);
}
</script>
<body onload="myFun()">
</html> 


:)
Was This Post Helpful? 0
  • +
  • -

#7 shriek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 26-June 09

Re: How to close XmlDocument file?

Posted 23 July 2009 - 11:20 AM

Ok adding the quote didn't really help..on the other hand I didn't really explain what the problem was. Anyway the problem is that if I change something in my xml file (in this case news.xml) then it should show different filesize but somewhy it keeps showing the same filesize even after the file has changed

let my news.xml file be:-
<news>
<item>hello world</item>
<item>goodbye world</item>
</news>

Was This Post Helpful? 0
  • +
  • -

#8 shriek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 26-June 09

Re: How to close XmlDocument file?

Posted 29 July 2009 - 06:15 PM

anyone ..no?? no??
Was This Post Helpful? 0
  • +
  • -

#9 forest51690  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 58
  • View blog
  • Posts: 340
  • Joined: 20-March 09

Re: How to close XmlDocument file?

Posted 29 July 2009 - 08:07 PM

function myFun()
{
var firstSz = "<?php echo filesize('news.xml')?>";
myFun2();
}
function myFun2()
{
var newSz = "<?php clearstatcache(); echo filesize('news.xml')?>";
alert(newSz);
setTimeout(function(){myFun2();},5000);
}


The PHP code does not get evaluated by the browser. The PHP code gets evaluated and the output sent where the code was. So when the browser reads the page, it sees this:
function myFun()
{
var firstSz = "10000";
myFun2();
}
function myFun2()
{
var newSz = "20000000";
alert(newSz);
setTimeout(function(){myFun2();},5000);
}


View source on your web page and you'll see what I'm talking about.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1