Hello bloke,
There are two things to discuss here. First is how your widget will receive data through XML; the second is that your server must also send the correct headers to the widget.
On 1, here is a sketch for a framework for the communication with server.
var objRequest = new XMLHttpRequest();
// call this to retrieve data from server
function getFromServer()
{
var strURL = "http://www.yourserver.com/api.php";
// specify a callback function to be called by the engine when
// data becomes available on the connection
objRequest.onreadystatechange = onDataReceived;
// initiate the request
objRequest.open( "GET", strURL, true );
objRequest.send();
}
// this is the callback function - will be called when data becomes available
function onDataReceived()
{
// only do something if everything OK
if (objRequest.status == 200)
{
// use XPath support for parsing the retrieved XML
var element = doc.evaluate( "response/news/data" );
// SEEME - double check this syntax - not sure if it's accurate!
for (var entry in element.item(0).childNodes)
{
text = entry.item(0).data;
// do something with the text
...
}
}
}
Now on 2: the code that you pasted above doesn't return "pure" XML and doesn't specify headers such as "text/xml". To fix this, you should probably format the server's output such as:
<?xml version="1.0" encoding="UTF-8"?>
<response>
<news>
<data>
...
</data>
</news>
<inhalt>
<data>
...
</data>
</inhalt>
</response>
and also send the headers with a call like below:
header("Content-type: text/xml;");