f



XML Node, HTML Node

hi guys,

how can distinguish between XML Node and HTML Node, using attributes or
method ..

thanks .

0
alhalayqa
1/9/2008 1:45:20 PM
comp.lang.javascript 38370 articles. 2 followers. javascript4 (1315) is leader. Post Follow

5 Replies
781 Views

Similar Articles

[PageSpeed] 41

alhalayqa wrote:

> how can distinguish between XML Node and HTML Node, using attributes or
> method ..

In the XML DOM nodes do not have an id property or a className property 
while in the HTML DOM nodes do have those properties.
On the other hand there are specializations of the XML DOM like the SVG 
DOM where id or className are properties too. Thus if you parse XML with 
  namespaces with browsers like Mozilla or Opera the parser recognizes 
namespaces like the XHTML 1 namespace or the SVG namespace and you get 
XHTML elements or SVG elements having id and className properties.

What exactly is it that you want to achieve?


-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/
0
Martin
1/9/2008 2:31:13 PM
well,
I am try to overwrite the setAttribute, getAttribute properties for only HTML
Nodes(only Element Nodes) and not for the XML Nodes. since the two properties
are defined for both XML,HTML Nodes, I just want to handle those for HTML
Node and return the default case for Non HTML Nodes.

thanks, 


Martin Honnen wrote:
>> how can distinguish between XML Node and HTML Node, using attributes or
>> method ..
>
>In the XML DOM nodes do not have an id property or a className property 
>while in the HTML DOM nodes do have those properties.
>On the other hand there are specializations of the XML DOM like the SVG 
>DOM where id or className are properties too. Thus if you parse XML with 
>  namespaces with browsers like Mozilla or Opera the parser recognizes 
>namespaces like the XHTML 1 namespace or the SVG namespace and you get 
>XHTML elements or SVG elements having id and className properties.
>
>What exactly is it that you want to achieve?
>

0
alhalayqa
1/9/2008 3:21:51 PM
Martin Honnen wrote:
> alhalayqa wrote:
> 
>> how can distinguish between XML Node and HTML Node, using attributes or
>> method ..
> 
> In the XML DOM nodes do not have an id property or a className property 
> while in the HTML DOM nodes do have those properties.
> On the other hand there are specializations of the XML DOM like the SVG 
> DOM where id or className are properties too. Thus if you parse XML with 
>  namespaces with browsers like Mozilla or Opera the parser recognizes 
> namespaces like the XHTML 1 namespace or the SVG namespace and you get 
> XHTML elements or SVG elements having id and className properties.
> 
> What exactly is it that you want to achieve?
> 
> 

I don't know about the OP, but I would like to write a JavaCode
routine that can get the value of the "class" attribute, from
either an HTMLor xhtml document.  I tried to use:

   var preNodeList = document.getElementsByTagName( "pre" );
   for ( var i = 0, len = preNodeList.length; i < len; ++i ) {
     var node = preNodeList[i];
     var classes = node.getAttribute("class");
   ...

But while that works in FF it fails in IE7.  What did I do wrong?

-Wayne
0
Wayne
1/9/2008 7:24:38 PM
alhalayqa wrote:
> I am try to overwrite the setAttribute, getAttribute properties for only HTML
> Nodes(only Element Nodes) and not for the XML Nodes.

Bad idea.  The owner objects are host objects.

> [Top post]

Please don't do that.  http://jibbering.com/faq/


PointedEars
-- 
    realism:    HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness:    XHTML 1.1 as application/xhtml+xml
                                                    -- Bjoern Hoehrmann
0
Thomas
1/9/2008 7:57:17 PM
On Jan 9, 2:24=A0pm, Wayne <nos...@all4me.invalid> wrote:
> Martin Honnen wrote:
> > alhalayqa wrote:
>
> >> how can distinguish between XML Node and HTML Node, using attributes or=

> >> method ..
>
> > In the XML DOM nodes do not have an id property or a className property
> > while in the HTML DOM nodes do have those properties.
> > On the other hand there are specializations of the XML DOM like the SVG
> > DOM where id or className are properties too. Thus if you parse XML with=

> > =A0namespaces with browsers like Mozilla or Opera the parser recognizes
> > namespaces like the XHTML 1 namespace or the SVG namespace and you get
> > XHTML elements or SVG elements having id and className properties.
>
> > What exactly is it that you want to achieve?
>
> I don't know about the OP, but I would like to write a JavaCode
> routine that can get the value of the "class" attribute, from
> either an HTMLor xhtml document. =A0I tried to use:
>
> =A0 =A0var preNodeList =3D document.getElementsByTagName( "pre" );
> =A0 =A0for ( var i =3D 0, len =3D preNodeList.length; i < len; ++i ) {
> =A0 =A0 =A0var node =3D preNodeList[i];
> =A0 =A0 =A0var classes =3D node.getAttribute("class");
> =A0 =A0...
>
> But while that works in FF it fails in IE7. =A0What did I do wrong?

It will fail in IE6 as well.  The getAttribute method in IE is broken
as designed.  Use:

classes =3D node.className;
0
David
1/10/2008 2:43:11 AM
Reply: