473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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
5 6201
VK

an********@gmail.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.documentElement) 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 "intelligence" 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********@gmail.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********@gmail.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
VK, Johannes, Thomas, Peter, RobG. Thanks for all the replies !

I think I have a much better understanding now.

What I am actually doing is : I am grabbing the xpath of an element(by
building it bottom-up at the client side) and then storing it on the
server. Then later I am retrieving that xpath and again tracing it back
for the same URL. But I am tracing it back using
XPathAPI.selectSingleNode on the server side, whereas I was building
the xpath on the client side using javascript.

So there was a little bit inconsistency in the way the two 'documents'
are intrepreted by two different parsers. (Jtidy,Xerces on the server
side and javascript on the client side)

I was converting the HTML to XHTML using JTidy and then parsing it
using Xerces at the server side.(So it 'was' XHTML on the server side,
so no TBODYs)

But I guess now I will parse it also on the client side using mozilla's
doc.evaluate (It's ok for me if it runs only on Mozilla)

I hope it works. Will let you know.

Thanks again,

Anupam

VK wrote:
an********@gmail.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.documentElement) 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 "intelligence" 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 #5
VK

an********@gmail.com wrote:
I was converting the HTML to XHTML using JTidy and then parsing it
using Xerces at the server side.(So it 'was' XHTML on the server side,
so no TBODYs)

But I guess now I will parse it also on the client side using mozilla's
doc.evaluate (It's ok for me if it runs only on Mozilla)

I hope it works. Will let you know.


It will not work - but you may try out of interest. First of all IE
doesn't support XHTML at all - it will be parsed as malformed HTML
Transitional with the most funny results (and the most fancy trees) to
expect. Given the phantom nodes problem on the standard-compliant
company plus some little but nasty DOM parsing discrepancies between
different browsers... I would say your idea of server-side /
client-side matching xpath's is like running two random numbers
generators on two machines and hope that the sequences will match.

I would suggest to use xpath in the environment it was intended to:- in
XSLT templates to process XML data part. With .xml (data) and .xsl
(transformations) you'll get what you want in the cross-browser way.

Apr 2 '06 #6

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

Similar topics

4
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...
13
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....
9
by: Lyners | last post by:
Quick question. I have some java script that looks like this; ...
2
by: dominic.martin | last post by:
Hi, I'm no javascript programmer but I found a really good piece of javascript at http://www.isdntek.com/tagbot/zipzoom.htm that magnifies areas of an image. It's just what I want but their...
4
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...
1
by: TKapler | last post by:
I think i am quite experienced javascript programmer, but I got a problem. I have a selectbox with e.g. 17 optgroups with 100 options. I need a javascript code to hide some of that optgroups (i...
7
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...
8
by: javascript | last post by:
I have a DataTable that I created in C# that looks like. Column1 - Column2 - Column3 1 - a - b 2 - c - d 3 - e - f Now if I want to get the value of column 3 with id 3 I simply need to do...
3
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.