473,597 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getElementsByTa gName

I am trying to parse responseXML from an HTTP request.
var doc = request.respons eXML;
var elements = doc.getElements ByTagName("*");
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.
Jul 23 '05 #1
23 15578
Michel Bany escribió:
I am trying to parse responseXML from an HTTP request.
var doc = request.respons eXML;
var elements = doc.getElements ByTagName("*");
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.


I think that the function getElementsByTa gName 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 getElementsByTa gName_IE(sTag){
if ((!sTag)||(sTag =='')||(sTag==' *')){
return window.document .all;
}

return document.all.ta gs(sTag);
}
window.document .getElementsByT agName = getElementsByTa gName_IE;
}

Regards,

knocte

--
Jul 23 '05 #2
On Fri, 08 Jul 2005 01:27:54 +0200, knocte
<kn****@NO-SPAM-PLEASE-gmail.com> wrote:
function IsIE(){
return window.document .all?true:false ;
}


this is not a remotely acceptable way of detecting if the behaviour of
getElementsByTa gName("*") 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.getEl ementsByTagName ) {
var els=document.ge tElementsByTagN ame("*");
if (els.length==0) {
// do whatever...
}
}
Jim.
Jul 23 '05 #3
Michel Bany wrote:
I am trying to parse responseXML from an HTTP request.
var doc = request.respons eXML;
var elements = doc.getElements ByTagName("*");
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.


Something like the following should do the trick:

function getEmAll() {
var els;
if ( document.getEle mentsByTagName ) {
els = document.getEle mentsByTagName( '*');
}
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
Jul 23 '05 #4
Michel Bany <m.****@wanadoo x.fr> wrote in message news:42******** **************@ news.wanadoo.fr ...
I am trying to parse responseXML from an HTTP request.
var doc = request.respons eXML;
var elements = doc.getElements ByTagName("*");
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.


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 getElementsByTa gName wildcard.

var allElements=doc ument.all || document.getEle mentsByTagName( "*");

if(typeof allElements != 'undefined' && allElements.len gth)
...

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.getEle mentsByTagName( "*"), probably the html element.
function getElements(all Elems, 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(all Elems,obj.child Nodes[i])
}
}

var allElements=[];
getElements( allElements, document.childN odes[0])
--
Stephen Chalmers
547265617375726 520627572696564 206174204F2E532 E207265663A2054 51323437393134

Jul 23 '05 #5
ASM
Jim Ley wrote:

if (document.getEl ementsByTagName ) {
var els=document.ge tElementsByTagN ame("*");
if (els.length==0) {
// do whatever...
}
}


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
Jul 23 '05 #6


Michel Bany wrote:
I am trying to parse responseXML from an HTTP request.
var doc = request.respons eXML;
var elements = doc.getElements ByTagName("*");
the last statement returns an empty collection when running from IE6.


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
getElementsByTa gName("*") gives you an empty collection?
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #7
On 08/07/2005 07:28, ASM wrote:

[snip]
IE is not reactive with this ccs rule :
td { color: blue }
td:hover { color: red }
IE is deficient and doesn't recognise the hover pseudo-class on any
elements except A.
if(document.all ) being digested by others browsers than IE
which detection have I to place in my code in this case ?


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.get ElementsByTagNa me) {
collection = document.getEle mentsByTagName( '*');
}

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

/* 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.getByTagNa me = useDOM;
} else {
e = useTags(a, tN);
if(e.length) {this.getByTagN ame = useTags;}
}
}
return e;
}
function useDOM(a, tN) {
return a.getElementsBy TagName(tN);
}
function useEmpty() {return [];}
function useTags(a, tN) {
return ('*' == tN) ? a.all : a.all.tags(tN);
}
return function(a, tN) {
this.getByTagNa me = isGenericObject (a.getElementsB yTagName)
? isObject(a.all) && isObject(a.all. tags)
? tryDOM
: useDOM
: isObject(a.all) && isObject(a.all. tags)
? useTags
: useEmpty;

return this.getByTagNa me(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.
Jul 23 '05 #8
ASM
Michael Winter wrote:

IE is deficient and doesn't recognise the hover pseudo-class on any
elements except A.
Yes, it's what I said (or approx)
and it is exactly what I want to detect.
if(document.all ) being digested by others browsers than IE
which detection have I to place in my code in this case ?

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.get ElementsByTagNa me) {
collection = document.getEle mentsByTagName( '*');
}


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)

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

/* 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 = [];
}
}
I think that test is quite egal if(document.all )
and doesn't permit to say : there is IE and IE only
More self-contained (but much more complex):
so complex that I understand anything
does that do what I want ?
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.getByTagNa me = useDOM;
}
else {
e = useTags(a, tN);
if(e.length) {this.getByTagN ame = useTags;}
}
}
return e;
}
function useDOM(a, tN) {
return a.getElementsBy TagName(tN);
}
function useEmpty() {return [];}
function useTags(a, tN) {
return ('*' == tN) ? a.all : a.all.tags(tN);
}
return function(a, tN) {
this.getByTagNa me = isGenericObject (a.getElementsB yTagName)
? isObject(a.all) && isObject(a.all. tags)
? tryDOM
: useDOM
: isObject(a.all) && isObject(a.all. tags)
? useTags
: useEmpty;

return this.getByTagNa me(a, tN);
};
})();


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

--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #9
On 09/07/2005 00:58, ASM wrote:
Michael Winter wrote:
IE is deficient and doesn't recognise the hover pseudo-class on any
elements except A.
Yes, it's what I said (or approx)


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.
and it is exactly what I want to detect.
That's the first time you've said as much.

[snip]
var collection;

/* If gEBTN is supported, attempt to use it. */
if(document.get ElementsByTagNa me) {
collection = document.getEle mentsByTagName( '*');
}


Does IE Windows unsupport this collection ?


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 getElementsByTa gName method at all.
I want to detect IE and IE only
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.
Or much better :
I want to detect browsers
which don't recognise pseudo-class (eventualy except on tag A)
You can't do that.

[snipped getElementsByTa gName emulation]
As I understood anything, does this getByTagName return false if
pseudo-class not allowed for tags TD ?


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 getElementsByTa gName
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="th is.className='o n-hover';"
onmouseout="thi s.className=''; ">...</td>

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4496
by: 2obvious | last post by:
This is a pipe dream, I realize, but I'm trying to emulate the functionality of the W3C DOM-supported document.getElementsByTagName method under the very nightmarish Netscape 4. Through some sleuthing, I was able to find what serves as a document.getElementById emulator at http://www.xs4all.nl/~ppk/js/dhtmloptions.html#versionb. (Below is the code; this clever algorithm is painstakingly explained at the site above.)
3
33271
by: Andy | last post by:
Hello, I have the following example XML: <data> <package> <packageid>123</packageid> <package_article> <articleid>article1</articleid> </package_article> </package>
7
7126
by: Dima | last post by:
Call to XmlNode.GetElementsByTagName returns XmlNodeList that stays in sync with XmlDocument thanks to events fired by XmlDocument. Once this list is created there is no way to remove its event handlers from the document. Calling GetElementsByTagName second time for the same tag name will create new list and add more event handlers. As result over time these handlers accumulate and reach pretty high number (millions). Every modification...
2
8653
by: JJA | last post by:
Here is my entire XML file - simplified to one node for testing: <root> <FlasConustbl> <ID>42101</ID> <AWARD>P015B030001</AWARD> <INSTITUTION_KEY>300</INSTITUTION_KEY> <INSTITUTION>Boston University</INSTITUTION> <WORLDAREA>Africa</WORLDAREA> <STREET>270 Bay State Road</STREET>
1
2595
by: Max | last post by:
Hello everyone! i would want to know if the getElementsByTagName() function starts to find the elements from documentElement comprising the same documentElement. XML example: <?xml version="1.0"?> <exslt:module xmlns:exslt="http://exslt.org/documentation" xmlns="http://default-ns-outter" version="1" prefix="str" exslt:foo="bah" > ....
1
3565
by: Ben | last post by:
I have a web service that returns the following xml: <?xml version="1.0" encoding="utf-8" ?> <NewDataSet> <Addresses> <XML_F52E2B61-18A1-11d1-B105-00805F49916B> <CustomerAddressBase CustomerAddressId="259DA89E-3B3F-DB11-90EA-0016353D15C7" AddrName="PRIMARY" /> <CustomerAddressBase
4
6950
by: Ouray Viney | last post by:
Xml <ib>8.4.27.5</ib> python from xml.dom import minidom xmldoc = minidom.parse('C:\TestProfile.xml') xmldoc
15
5758
Dormilich
by: Dormilich | last post by:
I’m trying to do the following document.getElementsByTagName("sup").getElementsByTagName("a"); currently I have this because I somehow need to return a combined result NodeList // can’t prototype into NodeList because of Firefox if (!Object.getElementsByTagName && Object.length) { Object.prototype.getElementsByTagName = function(name) { // the only idea I got var div = document.createElement("div");
0
7965
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7885
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8380
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5426
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2399
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1493
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1231
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.