# Dashboard Widget + XML?



## Fahrvergnuugen (May 10, 2005)

I want to write a dashboard widget that displays the last 5 posts of a web forum that I run. I've written a PHP script that runs on the server and queries the database for the information then spits out the result as XML.

Now I'm lost. I have no idea how to get my widget to load & parse the XML file that the server is generating. I have written plenty of parsers in PHP & Actionscript but never in JavaScript. I don't even know where to begin...

Unfortunately the Apple Developer page for dashboard doesn't have ANYTHING regarding XML parsing.


----------



## HateEternal (May 10, 2005)

From what I understand the widget JavaScript is different than normal web JavaScript but in Web standard JavaScript you can do a obj.getElementsByTagName(sName) which will return an array of tag objects.


----------



## Fahrvergnuugen (May 10, 2005)

thanks, that looks like it should do the trick.
To get started though, how would you load the XML into an object?


----------



## HateEternal (May 10, 2005)

You could try using XMLHttpRequest


```
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "test.txt",true);
 xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {
   alert(xmlhttp.responseText)
  }
 }
 xmlhttp.send(null)
```

I got the example from here: http://jibbering.com/2002/4/httprequest.html


----------



## Fahrvergnuugen (May 10, 2005)

Yes, excellent!
Thank you very much.


----------

