Recent Widgets


Register for DashboardWidgets

Recent Forums Posts

Partners


iCompositions

MacDesktops.net

RSS Showcase
RSS Comments
RSS Forums

This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. Posted in: Widget Development

Fetching and Parsing XML Documents

Author Message
August



Joined: 27 Mar 2005
Posts: 1
Location: United States of America

Posted: Sun Jul 11, 2004 - 7:01 am    Post subject: Imported from The Dashboader Reply with quote

One of the great things about Konfabulator is that it has an easy way to fetch and parse XML and HTML documents. In Dashboard, however, I've yet to find an easy way to do this. Has anyone else figured this out?

Thanks!

August
View user's profile Send private message Visit poster's website Widgets
nathanziarek



Joined: 27 Mar 2005
Posts: 1

Posted: Sun Jul 11, 2004 - 7:01 am    Post subject: Imported from The Dashboader Reply with quote

I read about this method, and it seems as if that only works with XML files, not HTML. Is there any method any one knows of for grabbing the source of HTML files?

Thanks,

Nate
View user's profile Send private message Widgets
Chris



Joined: 27 Jan 2005
Posts: 344
Location: Durham, UK

Posted: Sun Jul 11, 2004 - 7:01 am    Post subject: Imported from The Dashboader Reply with quote

Hmm... not quite sure why you keep saying packet. This will give you the whole XML document rather than just one transmitted packet.

You'd have to keep polling it if you want to have constant updates, I would imagine.
View user's profile Send private message Send e-mail Visit poster's website AIM Address Widgets
Chris



Joined: 27 Jan 2005
Posts: 344
Location: Durham, UK

Posted: Sun Jul 11, 2004 - 7:01 am    Post subject: Imported from The Dashboader Reply with quote

I was actually just playing round with XMLHttpRequest for high scores for my gadgets and was thinking how nice it'd be to have this oNXML thing if I were to make a status bar for data retrieval... Although, I suppsoe I'd have to know the over all size I'm getting to do that effectively. Hmm...

Anyhoo - back on topic. Here's a little snippet I've whipped up for my high score thing:

var hs = new XMLHttpRequest();
hs.open("GET", "http://somewhere.com/something.xml", true);

hs.onreadystatechange = function() {
if (hs.readyState == 4) {
var high_score_data = hs.responseXML;
//now handle the stuff we have:
var scores = high_score_data.getElementsByTagName("something");
//do something else....
}
}
hs.send();

Does that help?

Looking at that link you posted, all of the above can be found in it...

I'm beginning to spend almost as much time on these forums as I do at macnn... Uh-oh

Edit: Don't know why I posted what I originally did. Brain freeze I think...
View user's profile Send private message Send e-mail Visit poster's website AIM Address Widgets
netbox



Joined: 27 Mar 2005
Posts: 5
Location: Netherlands

Posted: Sun Jul 11, 2004 - 7:01 am    Post subject: Imported from The Dashboader Reply with quote

Chris, can you give me a little example how I can do this
in the javascript ?

I think you are one of the first one's who really
understand what I want.

I can't find out how to do this with xmlhttprequest, i miss
the onXML as i mentioned before

netbox
View user's profile Send private message Send e-mail Widgets
Chris



Joined: 27 Jan 2005
Posts: 344
Location: Durham, UK

Posted: Sun Jul 11, 2004 - 7:01 am    Post subject: Imported from The Dashboader Reply with quote

Ah right - well, you can listen for the ready state to go to 4 (once the whole XML document has streamed to you) and the just use var something = yourxmlhttpreqobject.responseXML to have a fully loaded XMLDOMDocument in that variable.

Which means it's parsed into a traversable DOM document automagically. So you just use standard methods like childNodes[index] and stuff to get at the data. Very easy, very nice, very quick.
View user's profile Send private message Send e-mail Visit poster's website AIM Address Widgets
netbox



Joined: 27 Mar 2005
Posts: 5
Location: Netherlands

Posted: Sun Jul 11, 2004 - 7:01 am    Post subject: Imported from The Dashboader Reply with quote

Yes exactly,
when connected to a (xml) stream,
the onXML is triggered after receiving each XML packet.
So that can trigger futher parsing. While listening for the next packet.

This is so cool in Flash, only 6 lines and the xml is streamed
into youre program, incl. the triggering of the "parse" code.

netbox
View user's profile Send private message Send e-mail Widgets
Chris



Joined: 27 Jan 2005
Posts: 344
Location: Durham, UK

Posted: Sun Jul 11, 2004 - 7:01 am    Post subject: Imported from The Dashboader Reply with quote

onXML? What's that? Sounds like something similar to onReadyStateChange, but I don't know..
View user's profile Send private message Send e-mail Visit poster's website AIM Address Widgets
netbox



Joined: 27 Mar 2005
Posts: 5
Location: Netherlands

Posted: Sun Jul 11, 2004 - 7:01 am    Post subject: Imported from The Dashboader Reply with quote

I'm thrilled with the possibility to easy import static XML documents,
but does anybody know if its possible to connect to a stream.

In Flash I use :
socket = new XMLSocket();
socket.connect('127.0.0.1', 8946);
socket.ignoreWhite = true;
socket.onXML = HandlePacket;
socket.onConnect = newConnection;
socket.onClose = endConnection;

Now I mis the onXML function
anybody suggestions ?

btw, I know my Flash runs, but I have trouble getting the
mouse events to it, and Dashboard is so freaking slick that
I want to move my Flash code to java Wink
View user's profile Send private message Send e-mail Widgets
netbox



Joined: 27 Mar 2005
Posts: 5
Location: Netherlands

Posted: Sun Jul 11, 2004 - 7:01 am    Post subject: Imported from The Dashboader Reply with quote

have a look at:
http://developer.apple.com/internet/webcontent/xmlhttpreq.html
View user's profile Send private message Send e-mail Widgets
Chris



Joined: 27 Jan 2005
Posts: 344
Location: Durham, UK

Posted: Sun Jul 11, 2004 - 7:01 am    Post subject: Imported from The Dashboader Reply with quote

Google for XMLHTTPRequest. Safari differs from Moz in it's implementation slightly.
View user's profile Send private message Send e-mail Visit poster's website AIM Address Widgets
Chris



Joined: 27 Jan 2005
Posts: 344
Location: Durham, UK

Posted: Sun Jul 11, 2004 - 7:01 am    Post subject: Imported from The Dashboader Reply with quote

Actually, it does work with HTML in the current pre-release builds of safari. It just doesn't form a proper DOM document out of it. To get round it I've been putting the innerHTML of some element to be the responseText and then using DOM methods that way. Works, but seems like a hack...
View user's profile Send private message Send e-mail Visit poster's website AIM Address Widgets
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.

 
Powered by phpBB © 2001, 2002 phpBB Group