View Full Version : Can you randomly load xml items or files with java?

07-24-2010, 08:17 PM
This is a weird idea I have- i will try to explain it all (forgive me if i do not).

i'm using xml to create dynamic content on the site i'm building for myself.
now, i know there is a way to randomly load xml content using php-
but i have zero experience with php (though i not afraid to learn it, if it is the only way to do this).

here's what i want to do:
i have (let's say) 4 "announcement" areas on a page, in addition to a "random info" bar off to the side. in each of these, i want to have randomly loaded xml content each time the page is refreshed/viewed.

so if i have a "recent site news" section on the page, i would have a folder for "some code" to look in to pull out an xml file to display. etc etc.

basically, i'm wondering if there is a java way to do this (perhaps similar to the choosePic function?). it doesn't have to load a different xml file each time the page is refreshed either- if there's a way to pick a set number of items from any xml file i specify- that would be ok too.

any help would be greatly appreciated.

Philip M
07-24-2010, 09:11 PM
This is the JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names.

JavaScript is purely a client-side language, and unless used with an Ajax call has no capability to read from or write to a file (except a cookie), communicate with the server, access a database, the client's operating system or the Windows registry, or alter the default behaviour of the browser.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

07-26-2010, 03:17 AM
my apologies for not using the full term and confusing you. i am talking about javascript.

Old Pedant
07-26-2010, 05:50 AM
Philip's answer was not only correct but it also makes a real difference in your question.

Yes, what you want to do is easily possible with JAVA.

Java has all the capabilities of PHP and then some.

What you want can *NOT* be done using JavaSCRIPT *UNLESS* the XML file(s) in question are from the SAME DOMAIN as the web page that is attempting to read them.

JavaSCRIPT does *NOT* support "cross site scripting" or "cross site access".

So you see, it makes a huge difference.

*ARE* you talking about XML files from the same domain? If so, then yes, you can do this. Not too hard, either. And if you just look in this forum, this same question was answered within the last week or two, I'm pretty sure. If I'm wrong though, or if you can't find the relevant answer and code, ask again. Assuming these are same-domain files.

07-27-2010, 10:38 AM
yes, they are all from the same domain.

Old Pedant
07-27-2010, 07:57 PM
Then, yes, you certainly can do this.

After all, that's exactly what AJAX is all about: Asynchronous Javascript And Xml.

Tons and tons of articles on AJAX out there. Tons of examples.

If you want to do this at page load time, you might not need to use the "A" in AJAX. You can use Synchronous calls, instead.

Oh, w.t.h. ... let me find a tutorial...


Look especially at this page:

and if you want to do this at page load time, look at the section that is titled "Async = false"

07-28-2010, 10:32 AM
the second link sounds like a concept that could definitely work out, from what i've read so far. i'll have to try it out. thanks old pedant!

i've uploaded the "template page" i made to try this idea out at http://onkodjinn.vacau.com/ if you want to see what i originally started with.