Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - javascript parentNode >Thread Next - Re: javascript parentNode Re: javascript parentNodeTo: NULL Date: 4/2/2006 4:13:00 AM anupamjain@g... 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. | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
