473,574 Members | 2,357 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

javascript parentNode

An interesting thing is happening. My table doesnt have 'TBody', but
the elem.parentNode .tagName is returning 'TBody' where elem refers to
the 'tr' tag.

Shouldnt it be returning 'table' ?

<body>
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
</body>

Also, its adding html tag even if its not present in the document (if I
lookup parentNode of body). Is there a way to tell javascript not to be
intelligent? (because I am building an xpath and I want to extract the
exact xpath from the real-world-html-document)

Thanks,
Anupam

Apr 2 '06 #1
14 3607
VK

an********@gmai l.com wrote:
An interesting thing is happening. My table doesnt have 'TBody', but
the elem.parentNode .tagName is returning 'TBody' where elem refers to
the 'tr' tag.

Shouldnt it be returning 'table' ?
The TBODY element is exposed for all tables, even if the table does not
explicitly define a TBODY element. (True for IE at least => 90% of
UA's)

Same for HTML (=> document.docume ntElement) It is actually an
obligatory element for HTML documents, unlike say <body>.
Is there a way to tell javascript not to be
intelligent? (because I am building an xpath and I want to extract the
exact xpath from the real-world-html-document)
JavaScript has nothing to do with it. The "intelligen ce" is
demonstarated by browser DOM parser. You seem mixing two very different
issues here: i) the source HTML code representing a page and ii) DOM
tree built on the basis of this source code.

You can retrieve any HTML source by using say responseText from an
ajaxoid and study it line by line. Here it is not important how many
rude mistakes is made in the layout, because it is just plain text for
you.

But with xpath and DOM methods you are dealing with the parsing
*results*, and these results can be far away of what is written in the
code. More poorly written code -> more efforts UA needs to spend to
build some reasonnable DOM tree -> more this DOM tree may differ from
the one intended in the obscured author's mind.
From the other side without DOM tree ready you cannot work with it. So

for xpath you just have to drop the idea to study the source and
concentrate on source parsing results:- bearing in mind that these
results may differ significally from one browser to another.

An alternative solution would be only to write your very own HTML
parser and feed the source into it over responseText.

P.S. It is actually strange that you are worring about such small and
easy to fix issues. I would expect you being nocked by phantom nodes on
tags' borders in W3C-victimized browsers (cannot say "W3C-compliant" in
this particular case). Either you already solved it or did not noticed
yet.

Apr 2 '06 #2
an********@gmai l.com wrote:
An interesting thing is happening. My table doesnt have 'TBody', but
the elem.parentNode .tagName is returning 'TBody' where elem refers to
the 'tr' tag.

Shouldnt it be returning 'table' ?

<body>
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
</body>


As you posted to an XML group, I assume that the above is XHTML, not
HTML. In the case of HTML, the tbody element would be there implicitly,
even if you did not write it in your code. In the case of XHTML, it
would not be there.

In general: for HTML use HTML tools, for XHTML use XML tools.

If you have problems with HTML, post to an HTML group.
--
Johannes Koch
Spem in alium nunquam habui praeter in te, Deus Israel.
(Thomas Tallis, 40-part motet)
Apr 2 '06 #3
VK wrote:
an********@gmai l.com wrote:
An interesting thing is happening. My table doesnt have 'TBody', but
the elem.parentNode .tagName is returning 'TBody' where elem refers to
the 'tr' tag.

Shouldnt it be returning 'table' ?
The TBODY element is exposed for all tables, even if the table does not
explicitly define a TBODY element. (True for IE at least => 90% of
UA's)


Your figures are wrong, and they do not matter.
[...] I would expect you being nocked by phantom nodes on tags' borders in
W3C-victimized browsers (cannot say "W3C-compliant" in this particular
case).


There are no phantom nodes. There are specified white-space text nodes.
Stop applying your fantasies on standardized and implemented reality.
PointedEars
Apr 2 '06 #4
Thomas 'PointedEars' Lahn wrote:
VK wrote:
an********@gmai l.com wrote:
An interesting thing is happening. My table doesnt have 'TBody', but
the elem.parentNode .tagName is returning 'TBody' where elem refers to
the 'tr' tag.

Shouldnt it be returning 'table' ?

The TBODY element is exposed for all tables, even if the table does not
explicitly define a TBODY element. (True for IE at least => 90% of
UA's)


Your figures are wrong, and they do not matter.


Actually they matter quite a lot, but it is correct that TBODY is
optional but implied in HTML. The problem is that the DOM pretends
to mimic the requirements of an SGML parser.
[...] I would expect you being nocked by phantom nodes on tags' borders in
W3C-victimized browsers (cannot say "W3C-compliant" in this particular
case).


There are no phantom nodes. There are specified white-space text nodes.


The specification differs between SGML-style parsing and XML-style
parsing. XML has no phantom nodes but it does have disappearing nodes
in mixed content, which SGML only has in element content.

///Peter
--
XML FAQ: http://xml.silmaril.ie/
Apr 2 '06 #5
VK
Thomas 'PointedEars' Lahn wrote:
There are no phantom nodes. There are specified white-space text nodes.
Stop applying your fantasies on standardized and implemented reality.


You should stop living in fantasies, not me and nor the developers
community. This question was studied rather deeply - there is not any
written standard for *pretty-print of source code affecting DOM tree*.
Just again a piece of W3C text written so poorly that you can read it
in several ways at once.
If you have your own valuable considerations, please post in the famous
bug #26179 at<https://bugzilla.mozill a.org/show_bug.cgi?id =26179>

P.S. This bug is being switched through the entire year from
VERIFIED-OPEN-MAJOR (by the community) to VERIFIED-CLOSED-INVALID (by
Mozilla) This game goes rather intensively so I cannot predict its
current status as of today.

P.P.S I do not participate in the "switch it" game - I'm just a reader
- and one of victimes of someone's non-rightified stuberness.

Apr 2 '06 #6
an********@gmai l.com wrote:
An interesting thing is happening. My table doesnt have 'TBody', but
the elem.parentNode .tagName is returning 'TBody' where elem refers to
the 'tr' tag.
You mean tr element.

Shouldnt it be returning 'table' ?
No. Most browsers, reading your markup, will assume HTML. In HTML, a tbody
element is mandatory in a table but the tags are optional. By omitting the
tags, you are allowing the browser to create tbody elements where it
considers appropriate.

<body>
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
</body>

Also, its adding html tag even if its not present in the document (if I
lookup parentNode of body). Is there a way to tell javascript not to be
intelligent? (because I am building an xpath and I want to extract the
exact xpath from the real-world-html-document)


You are using script to look at the document object model (DOM) that is
created from your HTML. JavaScript is just reporting what the browser has
created.

There is no way JavaScript can return the original HTML that created the
DOM - even innerHTML will return a serialised version of the DOM, not the
source markup.

You should not expect serialised DOM objects to be identical to the
original markup.
--
Rob
Apr 2 '06 #7
Peter Flynn wrote:
Thomas 'PointedEars' Lahn wrote:
VK wrote:
an********@gmai l.com wrote:
An interesting thing is happening. My table doesnt have 'TBody', but
the elem.parentNode .tagName is returning 'TBody' where elem refers to
the 'tr' tag.

Shouldnt it be returning 'table' ?
The TBODY element is exposed for all tables, even if the table does not
explicitly define a TBODY element. (True for IE at least => 90% of
UA's) Your figures are wrong, and they do not matter.


Actually they matter quite a lot,


That is shortsighted thinking. It is the World Wide Web, not the Internet
Explorer Web. Interoperabilit y is what counts, so it does not matter
whether the /supposed/ _current_ market share of a user agent is 10% or
90%. Not supporting the other UA because one depends on proprietary
features and behavior reduces the number of your potential visitors by 10%
or 90%. Likewise is your expected profit margin reduced by that number if
you run a commercial Web site, although that could have been avoided. I
would not call that being reasonable or responsible behavior, especially
when the additional costs (time, manpower) to accomplish interoperabilit y
are this low in the beginning. In fact, the maintenance costs in the
mid-term are considerably higher for a proprietary-only approach compared
to the costs accounted for if you targeted interoperabilit y from the
beginning. Some major companies had to and still have to recognize this
now, when they used IE-only code before and now want to support Firefox
as well (Intranets included). Do not make the same mistake.
but it is correct that TBODY is optional but implied in HTML. The problem
is that the DOM pretends to mimic the requirements of an SGML parser.


It is not a problem at all, and nothing is mimicked here. The DOM is
created on what is parsed, including elements that are optional or have
optional start/end tags.
[...] I would expect you being nocked by phantom nodes on tags' borders
in W3C-victimized browsers (cannot say "W3C-compliant" in this
particular case).

There are no phantom nodes. There are specified white-space text nodes.


The specification differs between SGML-style parsing and XML-style
parsing. XML has no phantom nodes but it does have disappearing
nodes in mixed content, which SGML only has in element content.


How did you get that idea?
PointedEars
Apr 2 '06 #8
VK wrote:
Thomas 'PointedEars' Lahn wrote:
There are no phantom nodes. There are specified white-space text nodes.
Stop applying your fantasies on standardized and implemented reality.


You should stop living in fantasies, not me and nor the developers
community. This question was studied rather deeply - there is not any
written standard for *pretty-print of source code affecting DOM tree*.

^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^
You are not making any sense. No surprise here, though.
PointedEars
Apr 2 '06 #9
VK

Thomas 'PointedEars' Lahn wrote:
VK wrote:
there is not any
written standard for *pretty-print of source code affecting DOM tree*. ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^
You are not making any sense. No surprise here, though.


You are demonstrating a lack of practical experience - no surprise
here, though. First check the definition of pretty-print (I actually
prefer the old term "indentations") .

Now count the nodes in (or simply look at this in DOM Inspector):

<!-- Conventional pretty-print -->
<form name="frm01" method="post" action="foobar. cgi">
<fieldset>
<legend>Demo</legend>
<label for="foo">Foo:</label>
<input type="text" name="foo" id="foo" accesskey="f">
</fieldset>
</form>
<!-- W3C's idioticy fighting pretty-print -->
<form name="frm01" method="post" action="foobar. cgi"<fieldset><leg end>Demo</legend
<label for="foo">Foo:</label
<input type="text" name="foo" id="foo" accesskey="f"</fieldset
</form>


P.S. On of rare moments when I'm ready to say "W3C MUST DIE!".

Apr 2 '06 #10

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

Similar topics

4
11939
by: rick | last post by:
The following basic script works fine in firefox by not in IE. Can anyone spot the problem? In IE I can only delete the first line but not the lines created by javascript. Also, look at the HTML code for the first line (click the Table HTML button:)) you will fine that the code displayed is not the same as was written. "onChange" was changed...
13
2642
by: Lyners | last post by:
I have a web page writen in ASP.NET that contains some javascript so that when a user presses a button, or edits a certain field in a datagrid, another cell in the datagrid is filled with a value. My probelm.... when I have the user press the update button (which does a post back that loops through the datagrid and updates a database) the...
9
2722
by: Lyners | last post by:
Quick question. I have some java script that looks like this; imgObj.parentNode.parentNode.childNodes(10).childNodes(0).value=imgObj.parentNode.parentNode.childNodes(6).innerText-imgObj.parentNode.parentNode.childNodes(9).childNodes(0).value This takes a cell in a datagrid (innertext) and subtracts the value of a text box (value) in another...
5
6212
by: anupamjain | last post by:
An interesting thing is happening. My table doesnt have 'TBody', but the elem.parentNode.tagName is returning 'TBody' where elem refers to the 'tr' tag. Shouldnt it be returning 'table' ? <body> <table> <tr> <td>1</td>
4
6312
by: bboyle18 | last post by:
Hi, I am working with a table sorting script which can be found here http://www.workingwith.me.uk/articles/scripting/standardista_table_sorting This script works very nicely, but when there is a large amount of data to sort e.g > 200 then there is a slight delay in the table sort. To cater for this I want to provide some feedback to the...
7
3204
by: julian.tklim | last post by:
Hi, I need to build an editable Datagrid with add & delete buttons on each row using javascript. DataGrid need not be pre-populated with values. To make the thing complicated, one of the column need to be a date picker field. I know things will be easier with ASPX datagrid.
3
2395
by: mportman300 | last post by:
Have pity on me.. i have been doing html, css, javascript squarely over 2 years... and am now doing a family project.. in my project i have decided to use a context menu script, its a menu that pretty much allows for when you right click on a page it shows you different links that the standard right click menu, link here:...
2
9021
by: joelkeepup | last post by:
Hi, I made a change this morning and now im getting an error that says either "a is undefined or null" or "e is undefined or null" the microsoft ajax line is below, I have no idea how to figure this problem out. Any suggestions? thanks Joel
0
1963
by: atencorps | last post by:
Hello I have the following code but need some help on it. The idea of the code is the main sections ie Service Management are viewable when the page is loaded and by clicking on the main titles/headings or clicking on the 'expand all' will allow you to view the items underneath each title/heading. The page seems to be broken at the...
0
7797
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...
0
7715
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...
0
8041
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. ...
0
8225
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...
0
8093
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5611
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3739
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2233
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
1333
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.