getElementsByTagName

V

VK

Martin said:
responseXML is not a method but a property and it is not part of the IE
object model but of the MSXML (Microsoft's XML parser) object model.

of IServerXMLHTTPRequest object model to be totally correct (if you
look for it on MSDN)

And
of course if the HTTP response is served as text/xml or application/xml
then MSXML tries to parse the response body and populates responseXML as
an XML DOM document if the markup is well-formed. No need to reparse
responseText.

Yep, by setting "text/xml" or "application/xml" response header you'll
make responseXML to work. Just how to do it on your local file system
(whyle testing/debugging)?
 
S

Stephen Chalmers

Michel Bany said:
This page http://www.siteexperts.com/tips/contents/ts16/page3.asp shows a recursive function that accesses all
elements. Modifying it to append to a supplied array, I found that it returns one element less than
document.getElementsByTagName("*"), probably the html element.


function getElements(allElems, obj)
{
for (var i=0;i < obj.childNodes.length;i++)
if (obj.childNodes.nodeType==1) // Elements only


allElems[allElems.length]=obj.childNodes;
getElements(allElems,obj.childNodes)
}
}

var allElements=[];
getElements( allElements, document.childNodes[0])

This recursive function works superbly with Firefox and Mozilla, but not
with IE6,
var request = new ActiveXObject("Microsoft.XMLHTTP");
<.. build and send the request ..>
var nodes = request.responseXML.childNodes[0];
I am getting an empty collection for nodes. What's wrong ?
Michel.


It worked for me under I.E.6, but I did have the same trouble under Mozilla on one page that used a doctype. After
removing the doctype the function worked properly, but not being a spec-basher I can't say why.
I would call the function as a last resort for when document.all and document.getElementById('*') can't deliver. To that
end, I've rewritten it to create and return its own array, so that its return value can be tested.

function getElements(obj)
{
var allElems=[];

for (var i=0; i < obj.childNodes.length; i++)
if (obj.childNodes.nodeType==1) // Elements only


allElems[ allElems.length ]=obj.childNodes;
allElems=allElems.concat( getElements(obj.childNodes) );
}

return allElems;
}
 
M

Michel Bany

Martin Honnen a écrit :
Michel Bany wrote:

var request = new ActiveXObject("Microsoft.XMLHTTP");
<.. build and send the request ..>
var nodes = request.responseXML.childNodes[0];
I am getting an empty collection for nodes. What's wrong ?



Hard to tell, check
request.status
request.statusText
request.getAllResponseHEaders()
then check
request.responseXML.parseError.errorCode
request.responseXML.parseError.reason
for IE, that should allow to tell what happens.
Yes, that helps. I could get the parse error : MSXML could not recognize
the &nbsp; entity in the xml.
Probably an old version.
I replaced the entity with   and everything is fine.
Thanks.
 
M

Martin Honnen

Michel Bany wrote:

I could get the parse error : MSXML could not recognize
the &nbsp; entity in the xml.
Probably an old version.

XML predefines only a few entities, contrary to HTML where nbsp is
defined as an entity.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top