Connecting Tech Pros Worldwide Help | Site Map

getElementsByTagName

Michel Bany
Guest
 
Posts: n/a
#1: Jul 23 '05
I am trying to parse responseXML from an HTTP request.
var doc = request.responseXML;
var elements = doc.getElementsByTagName("*");
the last statement returns an empty collection when running from IE6.
It returns the expected collection when running under Firefox or Mozilla.
Anybody can explain ?
Michel.
knocte
Guest
 
Posts: n/a
#2: Jul 23 '05

re: getElementsByTagName


Michel Bany escribió:[color=blue]
> I am trying to parse responseXML from an HTTP request.
> var doc = request.responseXML;
> var elements = doc.getElementsByTagName("*");
> the last statement returns an empty collection when running from IE6.
> It returns the expected collection when running under Firefox or Mozilla.
> Anybody can explain ?
> Michel.[/color]

I think that the function getElementsByTagName does not accept the
string "*" in IE. You will have to correct the DOM behaviour of IE with
something like this:

function IsIE(){
return window.document.all?true:false;
}

if (IsIE()) {
function getElementsByTagName_IE(sTag){
if ((!sTag)||(sTag=='')||(sTag=='*')){
return window.document.all;
}

return document.all.tags(sTag);
}
window.document.getElementsByTagName = getElementsByTagName_IE;
}

Regards,

knocte

--
Jim Ley
Guest
 
Posts: n/a
#3: Jul 23 '05

re: getElementsByTagName


On Fri, 08 Jul 2005 01:27:54 +0200, knocte
<knocte@NO-SPAM-PLEASE-gmail.com> wrote:
[color=blue]
>function IsIE(){
> return window.document.all?true:false;
>}[/color]

this is not a remotely acceptable way of detecting if the behaviour of
getElementsByTagName("*") returns what you want it to, document.all is
supported by a very large number of user agents, and is certainly not
a discriminator for IE!

if (document.getElementsByTagName) {
var els=document.getElementsByTagName("*");
if (els.length==0) {
// do whatever...
}
}


Jim.
RobG
Guest
 
Posts: n/a
#4: Jul 23 '05

re: getElementsByTagName


Michel Bany wrote:[color=blue]
> I am trying to parse responseXML from an HTTP request.
> var doc = request.responseXML;
> var elements = doc.getElementsByTagName("*");
> the last statement returns an empty collection when running from IE6.
> It returns the expected collection when running under Firefox or Mozilla.
> Anybody can explain ?
> Michel.[/color]

Something like the following should do the trick:

function getEmAll() {
var els;
if ( document.getElementsByTagName ) {
els = document.getElementsByTagName('*');
}
if ( ( !els || !els.length ) && document.all ) {
els = document.all;
}
return els;
}

Note you should check the returned value, there is still plenty of scope
for failure.

--
Rob
Stephen Chalmers
Guest
 
Posts: n/a
#5: Jul 23 '05

re: getElementsByTagName


Michel Bany <m.bany@wanadoox.fr> wrote in message news:42cd9eb6$0$1254$8fcfb975@news.wanadoo.fr...[color=blue]
> I am trying to parse responseXML from an HTTP request.
> var doc = request.responseXML;
> var elements = doc.getElementsByTagName("*");
> the last statement returns an empty collection when running from IE6.
> It returns the expected collection when running under Firefox or Mozilla.
> Anybody can explain ?
> Michel.[/color]

I get around this by giving priority to document.all if it is available. This will support I.E. but may not work for
some DOM browsers that do not support document.all or the getElementsByTagName wildcard.

var allElements=document.all || document.getElementsByTagName("*");

if(typeof allElements != 'undefined' && allElements.length)
...

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[i].nodeType==1) // Elements only


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

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


--
Stephen Chalmers
547265617375726520627572696564206174204F2E532E2072 65663A205451323437393134



ASM
Guest
 
Posts: n/a
#6: Jul 23 '05

re: getElementsByTagName


Jim Ley wrote:[color=blue]
>
> if (document.getElementsByTagName) {
> var els=document.getElementsByTagName("*");
> if (els.length==0) {
> // do whatever...
> }
> }[/color]

hello Jim,

IE is not reactive with this ccs rule :
td { color: blue }
td:hover { color: red }

if(document.all) being digested by others browsers than IE
which detection have I to place in my code in this case ?


--
Stephane Moriaux et son [moins] vieux Mac
Martin Honnen
Guest
 
Posts: n/a
#7: Jul 23 '05

re: getElementsByTagName




Michel Bany wrote:
[color=blue]
> I am trying to parse responseXML from an HTTP request.
> var doc = request.responseXML;
> var elements = doc.getElementsByTagName("*");
> the last statement returns an empty collection when running from IE6.[/color]

The wild card '*' is supported when I test here with MSXML 3 on Windows
XP and IE 6, I am not sure about earlier MSXML releases without testing.

Are you sure the XML is properly loaded and parsed when
getElementsByTagName("*") gives you an empty collection?


--

Martin Honnen
http://JavaScript.FAQTs.com/
Michael Winter
Guest
 
Posts: n/a
#8: Jul 23 '05

re: getElementsByTagName


On 08/07/2005 07:28, ASM wrote:

[snip]
[color=blue]
> IE is not reactive with this ccs rule :
> td { color: blue }
> td:hover { color: red }[/color]

IE is deficient and doesn't recognise the hover pseudo-class on any
elements except A.
[color=blue]
> if(document.all) being digested by others browsers than IE
> which detection have I to place in my code in this case ?[/color]

You don't perform any detection at all, at least in the sense of looking
for IE. What you're looking for is specific behaviour, and then an
alternative method of achieving what you want.

var collection;

/* If gEBTN is supported, attempt to use it. */
if(document.getElementsByTagName) {
collection = document.getElementsByTagName('*');
}

/* If the previous attempt failed... */
if(!collection || !collection.length) {

/* Check to see if we can use the all property
* to obtain a collection of all elements in
* the document.
*
* Note that this is *not* a check for IE, but
* a feature test.
*/
if(document.all) {
collection = document.all;

/* If not, return an empty array as failure. */
} else {
collection = [];
}
}


More self-contained (but much more complex):

var getByTagName = (function() {
function isGenericObject(value) {
return isObject(value) || ('function' == typeof value);
}
function isObject(value) {
return !!value && ('object' == typeof value);
}
function tryDOM(a, tN) {
var e = useDOM(a, tN);

if('*' == tN) {
if(e.length) {
this.getByTagName = useDOM;
} else {
e = useTags(a, tN);
if(e.length) {this.getByTagName = useTags;}
}
}
return e;
}
function useDOM(a, tN) {
return a.getElementsByTagName(tN);
}
function useEmpty() {return [];}
function useTags(a, tN) {
return ('*' == tN) ? a.all : a.all.tags(tN);
}
return function(a, tN) {
this.getByTagName = isGenericObject(a.getElementsByTagName)
? isObject(a.all) && isObject(a.all.tags)
? tryDOM
: useDOM
: isObject(a.all) && isObject(a.all.tags)
? useTags
: useEmpty;

return this.getByTagName(a, tN);
};
})();

What you'd use depends on whether you'd end up repeating code. The above
really boils down to something quite simple and efficient, though it may
not look like it at first glance.

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
ASM
Guest
 
Posts: n/a
#9: Jul 23 '05

re: getElementsByTagName


Michael Winter wrote:[color=blue]
>
> IE is deficient and doesn't recognise the hover pseudo-class on any
> elements except A.[/color]

Yes, it's what I said (or approx)
and it is exactly what I want to detect.
[color=blue][color=green]
>> if(document.all) being digested by others browsers than IE
>> which detection have I to place in my code in this case ?[/color]
>
>
> You don't perform any detection at all, at least in the sense of looking
> for IE. What you're looking for is specific behaviour, and then an
> alternative method of achieving what you want.
>
> var collection;
>
> /* If gEBTN is supported, attempt to use it. */
> if(document.getElementsByTagName) {
> collection = document.getElementsByTagName('*');
> }[/color]

Does IE Windows unsupport this collection ?

I want to detect IE and IE only
Or much better :
I want to detect browsers
which don't recognise pseudo-class (eventualy except on tag A)
[color=blue]
>
> /* If the previous attempt failed... */
> if(!collection || !collection.length) {
>
> /* Check to see if we can use the all property
> * to obtain a collection of all elements in
> * the document.
> *
> * Note that this is *not* a check for IE, but
> * a feature test.
> */
> if(document.all) {
> collection = document.all;
>
> /* If not, return an empty array as failure. */
> } else {
> collection = [];
> }
> }[/color]

I think that test is quite egal if(document.all)
and doesn't permit to say : there is IE and IE only
[color=blue]
> More self-contained (but much more complex):[/color]

so complex that I understand anything
does that do what I want ?
[color=blue]
> var getByTagName = (function() {
> function isGenericObject(value) {
> return isObject(value) || ('function' == typeof value);
> }
> function isObject(value) {
> return !!value && ('object' == typeof value);
> }
> function tryDOM(a, tN) {
> var e = useDOM(a, tN);
> if('*' == tN) {
> if(e.length) {
> this.getByTagName = useDOM;
> }
> else {
> e = useTags(a, tN);
> if(e.length) {this.getByTagName = useTags;}
> }
> }
> return e;
> }
> function useDOM(a, tN) {
> return a.getElementsByTagName(tN);
> }
> function useEmpty() {return [];}
> function useTags(a, tN) {
> return ('*' == tN) ? a.all : a.all.tags(tN);
> }
> return function(a, tN) {
> this.getByTagName = isGenericObject(a.getElementsByTagName)
> ? isObject(a.all) && isObject(a.all.tags)
> ? tryDOM
> : useDOM
> : isObject(a.all) && isObject(a.all.tags)
> ? useTags
> : useEmpty;
>
> return this.getByTagName(a, tN);
> };
> })();[/color]

As I understood anything, does this getByTagName return false if
pseudo-class not allowed for tags TD ?



--
Stephane Moriaux et son [moins] vieux Mac
Michael Winter
Guest
 
Posts: n/a
#10: Jul 23 '05

re: getElementsByTagName


On 09/07/2005 00:58, ASM wrote:
[color=blue]
> Michael Winter wrote:
>[color=green]
>> IE is deficient and doesn't recognise the hover pseudo-class on any
>> elements except A.[/color]
>
> Yes, it's what I said (or approx)[/color]

Your comment was, to me, so random and at a tangent to the current topic
that I read it as a question, rather than a statement.
[color=blue]
> and it is exactly what I want to detect.[/color]

That's the first time you've said as much.

[snip]
[color=blue][color=green]
>> var collection;
>>
>> /* If gEBTN is supported, attempt to use it. */
>> if(document.getElementsByTagName) {
>> collection = document.getElementsByTagName('*');
>> }[/color]
>
> Does IE Windows unsupport this collection ?[/color]

Again, I'm confused as to what you mean. Perhaps: "Will IE/Win ever
return a non-empty collection using this code?" If so, then yes, IE6
will return a collection containing all elements within the document, as
it should. IE5.x will always return an empty collection, and IE4 doesn't
support the getElementsByTagName method at all.
[color=blue]
> I want to detect IE and IE only[/color]

Browser detection is flawed, and has been since browsers first started
trying to spoof other browsers. However, you can use Microsoft's
conditional comments mechanism which is, as far as I know, only
implemented by IE.
[color=blue]
> Or much better :
> I want to detect browsers
> which don't recognise pseudo-class (eventualy except on tag A)[/color]

You can't do that.

[snipped getElementsByTagName emulation]
[color=blue]
> As I understood anything, does this getByTagName return false if
> pseudo-class not allowed for tags TD ?[/color]

You've only just explained your desire to detect the lack of support for
the :hover pseudo-class, so of course that code doesn't do what you
want. It accomplished what I read as the direction of discussion: how to
handle earlier IE versions which didn't support the getElementsByTagName
method properly.


You cannot detect what is supported in CSS via scripting. However, what
you can do is emulate some of that functionality. If you want to alter
the appearance of an element, then implement it in both CSS and script:

td {
background-color: transparent;
color: blue;
}

td.on-hover,
td:hover {
background-color: transparent;
color: red;
}


<td onmouseover="this.className='on-hover';"
onmouseout="this.className='';">...</td>

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Michel Bany
Guest
 
Posts: n/a
#11: Jul 23 '05

re: getElementsByTagName


[color=blue]
>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[i].nodeType==1) // Elements only
>
>
> allElems[allElems.length]=obj.childNodes[i];
> getElements(allElems,obj.childNodes[i])
> }
>}
>
>var allElements=[];
>getElements( allElements, document.childNodes[0])
>
>
>[/color]
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.
ASM
Guest
 
Posts: n/a
#12: Jul 23 '05

re: getElementsByTagName


Michael Winter wrote:

sory to have turned of a file from its original question
as mine would be seen as an extension ( ?)

thanks for your patience and answer
[color=blue]
> On 09/07/2005 00:58, ASM wrote:
>[color=green]
>> I want to detect browsers
>> which don't recognise pseudo-class (eventualy except on tag A)[/color]
>
> You can't do that.[/color]

[snip]

[color=blue]
> You cannot detect what is supported in CSS via scripting. However, what
> you can do is emulate some of that functionality. If you want to alter
> the appearance of an element, then implement it in both CSS and script:
>
> td {
> background-color: transparent;
> color: blue;
> }
>
> td.on-hover,
> td:hover {
> background-color: transparent;
> color: red;
> }
>
>
> <td onmouseover="this.className='on-hover';"
> onmouseout="this.className='';">...</td>[/color]

because I wouln't want charge css compatible browsers with events they
don't need (and aso not to much poluate html code)
and because I have double class (and theire hovers) on same element
(depend if selected or not)
by that my wanted is some more complex than a simple roll-over
I'd made a JS code attibutting at page loaded this events only if IE

exercices (tables rows or cells selections)
examples are (in french) here :
http://perso.wanadoo.fr/stephane.mor...ht_rows_fr.htm
more complex :
http://perso.wanadoo.fr/stephane.mor...t_cells_fr.htm
to compare with same for only css (and few JS)
http://perso.wanadoo.fr/stephane.mor..._cells_css.htm

all of them based on an ie dectection (mixed with iCab)
detection ignoring capabilities of other unknown browsers

--
Stephane Moriaux et son [moins] vieux Mac
Martin Honnen
Guest
 
Posts: n/a
#13: Jul 23 '05

re: getElementsByTagName




Michel Bany wrote:

[color=blue]
> 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 ?[/color]


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.



--

Martin Honnen
http://JavaScript.FAQTs.com/
VK
Guest
 
Posts: n/a
#14: Jul 23 '05

re: getElementsByTagName


> I am trying to parse responseXML from an HTTP request.[color=blue]
> var doc = request.responseXML;
> var elements = doc.getElementsByTagName("*");[/color]

responseXML doesn't work this way in IE. Overall it's a bogus method:
doesn't fail on calling it, but always gives you empty string for any
XML methods. If you *really* have a valid XML data from your server,
you have to use XML parser first:

....
if (window.XMLHttpRequest) {
// FF & Co
}
else {
try {
var myDataIsland = new ActiveXObject("Msxml3.DOMDocum*ent");}
catch (e1) {
var myDataIsland = new ActiveXObject("Msxml2.DOMDocum*ent");}
}
if (myDataIsland != null) {
var myInOutStream = new ActiveXObject("Microsoft.XMLHT*TP");
<pseudo-code - read data using myInOutStream>
<pseudo-code - if success>
myDataIsland.loadXML(myInOutSt*ream.responseText);
}
}
[color=blue]
>From this point forward myDataIsland contains perfectly formatted and[/color]
parsed XML data.

Now you can: var elm = myDataIsland.getElementsByTagName("*");
It works perfectly in IE.

All the above has sense only if you are really getting a valid XML from
your server. If it's just an unstructured set of strings you're calling
XML for convenience, then simply read your text and parse it manually
in the way you want:
var txt = myInOutSt*ream.responseText;
....

responseText method always works no matter what.

ASM
Guest
 
Posts: n/a
#15: Jul 23 '05

re: getElementsByTagName


VK wrote:[color=blue][color=green]
>>I am trying to parse responseXML from an HTTP request.
>>var doc = request.responseXML;
>>var elements = doc.getElementsByTagName("*");[/color]
>
>
> responseXML doesn't work this way in IE. Overall it's a bogus method:
> doesn't fail on calling it, but always gives you empty string for any
> XML methods. If you *really* have a valid XML data from your server,
> you have to use XML parser first:
>
> ...
> if (window.XMLHttpRequest) {
> // FF & Co
> }
> else {[/color]

if(document.all && navigator.userAgent.indexOf('Mac')<0)
[color=blue]
> try {[/color]

try is not understood by my NC 4.5 and gives an error
[color=blue]
> var myDataIsland = new ActiveXObject("Msxml3.DOMDocum*ent");}
> catch (e1) {
> var myDataIsland = new ActiveXObject("Msxml2.DOMDocum*ent");}
> }
> if (myDataIsland != null) {
> var myInOutStream = new ActiveXObject("Microsoft.XMLHT*TP");
> <pseudo-code - read data using myInOutStream>
> <pseudo-code - if success>
> myDataIsland.loadXML(myInOutSt*ream.responseText);
> }
> }
>[color=green]
>>From this point forward myDataIsland contains perfectly formatted and[/color]
> parsed XML data.
>
> Now you can: var elm = myDataIsland.getElementsByTagName("*");
> It works perfectly in IE.
>
> All the above has sense only if you are really getting a valid XML from
> your server. If it's just an unstructured set of strings you're calling
> XML for convenience, then simply read your text and parse it manually
> in the way you want:
> var txt = myInOutSt*ream.responseText;
> ...
>
> responseText method always works no matter what.
>[/color]


--
Stephane Moriaux et son [moins] vieux Mac
VK
Guest
 
Posts: n/a
#16: Jul 23 '05

re: getElementsByTagName


> try is not understood by my NC 4.5 and gives an error

With all my respect to the old glory of Netscape, NN 4.5 is out of the
scope of support as of the year 2005 (as well as IE 3.02, NN3 Gold,
NCSA Mozaic and others). If for some reasons you want to stay with NN4,
I suggest you at least upgrade to NN 4.71 (that was the last
cummulative upgrade for NN4). NN 4.5 was one of the most bugs-full in
the series.

ASM
Guest
 
Posts: n/a
#17: Jul 23 '05

re: getElementsByTagName


VK wrote:[color=blue][color=green]
>>try is not understood by my NC 4.5 and gives an error[/color]
>
> With all my respect to the old glory of Netscape, NN 4.5[/color]

:-)

On my old Mac, NC4.5 is (exept IE 5.1 (is it really a browser?))
the alone acceptable
You can also use Mozilla 1.02 (US) if you accept its 2 mn for loading
(and 20 seconds on each new popup)

Then, there are some countries where people are happy to can use
very old UC ... (without ADSL or DSL) and by the fact old browsers.

--
Stephane Moriaux et son [moins] vieux Mac
VK
Guest
 
Posts: n/a
#18: Jul 23 '05

re: getElementsByTagName


> On my old Mac, NC4.5 is the alone acceptable

And what's wrong with Opera?
<http://www.opera.com/download/?platform=mac>

Has its faults, but pretty stable, lightweight, and at least you can
work with modern DOM/scripting.

[color=blue]
> IE 5.1 (is it really a browser?))[/color]
It is, and a good one. Just don't tell it to anyone! :-X

ASM
Guest
 
Posts: n/a
#19: Jul 23 '05

re: getElementsByTagName


VK wrote:[color=blue][color=green]
>>On my old Mac, NC4.5 is the alone acceptable[/color]
>
>
> And what's wrong with Opera?[/color]

Opera 6.03 is a daube (buggued to the bone)
[color=blue]
> <http://www.opera.com/download/?platform=mac>[/color]

donwloaded just now
version 8 seems to run correctly on my new mac
I'll can be more friend with him (not to much cause pub)



--
Stephane Moriaux et son [moins] vieux Mac
Martin Honnen
Guest
 
Posts: n/a
#20: Jul 23 '05

re: getElementsByTagName




VK wrote:
[color=blue][color=green]
>>I am trying to parse responseXML from an HTTP request.
>>var doc = request.responseXML;
>>var elements = doc.getElementsByTagName("*");[/color]
>
>
> responseXML doesn't work this way in IE. Overall it's a bogus method:
> doesn't fail on calling it, but always gives you empty string for any
> XML methods.[/color]

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. 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.



--

Martin Honnen
http://JavaScript.FAQTs.com/
VK
Guest
 
Posts: n/a
#21: Jul 23 '05

re: getElementsByTagName




Martin Honnen wrote:[color=blue]
> VK wrote:
>[color=green][color=darkred]
> >>I am trying to parse responseXML from an HTTP request.
> >>var doc = request.responseXML;
> >>var elements = doc.getElementsByTagName("*");[/color]
> >
> >
> > responseXML doesn't work this way in IE. Overall it's a bogus method:
> > doesn't fail on calling it, but always gives you empty string for any
> > XML methods.[/color]
>
> 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.[/color]

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

[color=blue]
> 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.[/color]

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)?

Stephen Chalmers
Guest
 
Posts: n/a
#22: Jul 23 '05

re: getElementsByTagName


Michel Bany <m.bany@wanadoox.fr> wrote in message news:42cfd27b$0$25057$8fcfb975@news.wanadoo.fr...[color=blue]
>[color=green]
> >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[i].nodeType==1) // Elements only
> >
> >
> > allElems[allElems.length]=obj.childNodes[i];
> > getElements(allElems,obj.childNodes[i])
> > }
> >}
> >
> >var allElements=[];
> >getElements( allElements, document.childNodes[0])
> >
> >
> >[/color]
> 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.[/color]

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[i].nodeType==1) // Elements only


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

return allElems;
}

--
Stephen Chalmers


Michel Bany
Guest
 
Posts: n/a
#23: Jul 23 '05

re: getElementsByTagName


Martin Honnen a écrit :
[color=blue]
>
>
> Michel Bany wrote:
>
>[color=green]
>> 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 ?[/color]
>
>
>
> 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.
>
>[/color]
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.
Martin Honnen
Guest
 
Posts: n/a
#24: Jul 23 '05

re: getElementsByTagName




Michel Bany wrote:

[color=blue]
> I could get the parse error : MSXML could not recognize
> the &nbsp; entity in the xml.
> Probably an old version.[/color]

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


--

Martin Honnen
http://JavaScript.FAQTs.com/
Closed Thread