[nycphp-talk] XML(?) problem
corey szopinski
corey at domanistudios.com
Fri Feb 25 18:45:26 EST 2005
I¹ve just gone through something similar.
I read somewhere that the xml request object likes to see that the content
is served up as XML, so either the file extension ends in .xml or you have
the header set as header("Content-type: text/xml");
I¹m not sure if this makes any difference or not, but I have gotten it work.
I¹d also try alert(response); and make sure you get [object], if not, then
you know that something¹s not coming through correctly.
You can also pass your xmldoc into this quick and dirty recursive function
to see what you¹re working with:
/**
* DESCRIBE AN XML FILE BY RECURSIVE LISTING
*
* calls traverse() recursively to list out nodes and child nodes as list
items
*
*
** DON'T USE ON FIREFOX: the document.write overwrites the document object
(for reasons unknown)
*
* @param xml
*/
function describeXML(xmlDoc){
var root=xmlDoc.documentElement;
traverse(root);
//for(var i in xmlDoc){ document.write(i+"<br>"); }
/* this is interesting, but not too useful */
}
/**
* TRAVERSES AN XML NODE
*
* recursive function
* @param xml.node
*/
function traverse(tree) {
if(tree.hasChildNodes()) {
document.write('<ul><li>');
document.write(tree.tagName+' ('+tree.childNodes.length+') : ');
for(var i=0; i < tree.childNodes.length; i++){
traverse(tree.childNodes[i]);
}
document.write('</li></ul>');
}else{
document.write('<b>'+tree.nodeValue+'</b>');
}
}
On 2/25/05 4:49 PM, "Faber Fedor" <faber at linuxnj.com> wrote:
> I'm attemtping to write a webapp using the XMLHTTPRequest functionality
> as described over at
> http://www.xml.com/pub/a/2005/02/09/xml-http-request.html . I'm
> assuming someone in here has already done this. If not, anyone know the
> URL for the NY XML group (I saw mention of their existence, but no URL).
>
> My problem is here:
>
> function processReqChange()
> {
> // only if req shows "complete"
> if (req.readyState == 4) {
> // only if "OK"
> if (req.status == 200) {
> // ...processing statements go here...
> alert("getting the response");
> response = req.responseXML.documentElement;
>
> alert("So far, so good!");
> method = response.getElementsByTagName('method')[0].firstChild.data;
> alert("method = " + method);
> <snip>
>
> I successfully get to "getting the response" alert but it fails at the
> next line. The Javascript console complains that req.responseXML has no
> properties and javascript aborts the function (silently!).
> req.statusText says everything's OK and I can even see the text of the
> XML in req.responseText.
>
> So I'm guessing the error is that I don't have a wellformed XML
> document. Here is what I have:
>
> <?xml version="1.0"?>
> <response>
> <method>refreshQ</method>
> <result>My Results!</result>
> </response>
>
> which, to me, is well-formed.
>
> I googled for everything I can think of and came up with nada. Any
> suggestions?
Corey Szopinski
Director of Technology
DOMANI STUDIOS
corey at domanistudios.com
55 Washington St. Suite 822
Brooklyn, NY 11201
718-797-4470 x116
More information about the talk
mailing list