Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using XML in Widgets/Javascript



Hi,
I am trying to write a widget which uses a static XML file which would be bundled with the widget. I want the XML file to hold the data for items in a popup menu in the widget. So basically when the widget starts it needs to read the xml file to get the options in the menu. I've been trying to figure out how to do this in Javascript and have been striking out. I've discovered things like XMLHttpRequest(), but it doesn't seem to do exactly what I need. XMLHttpRequest has a method "load" which you call like: XMLHttpRequestObject.load("GET", url, null), where "url" is (I believe) a string representing the URL. So I thought if I set 'url' to a string representing the local file name I could read in a local xml file into a DOM object. (I've tried all kinds of strings representing the local file, the absolute path, the relative path, file://... file:/... etc.) This is all being done in an Html file containing some JS code opened in Safari, btw, I'm trying to get it to work as a regular HTML/Jscript file before trying to stuff it into a widget. Here's some of the relevant code I'm trying:


req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET", "searches.xml", true);
req.send(null);

...
// handle onreadystatechange event of req object
function processReqChange() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            clearTopicList();
            buildTopicList();
         } else {
            alert("There was a problem retrieving the XML data:\n"; +
                req.status + " : " + req.statusText);
         }
    }
}

It fails on the req.open... statement. I get the alert "There was a problem..." I've tried this with lots of different strings in the "searches.xml" I wonder if the problem is that it isn't set up to handle a local file, it wants to send the file request to an http server.

So, after all that, my question is simply: is there a way to load/ parse a local xml file into a DOM object in javascript that would work in a widget?

dave r.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Dashboard-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/dashboard-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.