473,395 Members | 2,783 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,395 software developers and data experts.

Fast way to find a text node element in DOM tree?

What's a good way to find a specific text node element in a web page's DOM
tree? I thought of traversing each node but there has to be a faster way.
Is there a "find text node by nodeValue" function or something? I do know
the nodeValue (text string) of the text node.

Thanks.
Aug 29 '05 #1
3 5458
Robert Oschler wrote:
What's a good way to find a specific text node element in a web page's DOM
tree? I thought of traversing each node but there has to be a faster way.
Is there a "find text node by nodeValue" function or something? I do know
the nodeValue (text string) of the text node.


What property do you intend to use to find it? It it selected by the
user? clicked on? a navigable element such as an anchor, link or input?

Using 'find by value' may be a tad difficult if you don't know the value
to find by.
--
Rob
Aug 29 '05 #2

"RobG" <rg***@iinet.net.au> wrote in message
news:uh*****************@news.optus.net.au...
Robert Oschler wrote:
What's a good way to find a specific text node element in a web page's DOM tree? I thought of traversing each node but there has to be a faster way. Is there a "find text node by nodeValue" function or something? I do know the nodeValue (text string) of the text node.


What property do you intend to use to find it? It it selected by the
user? clicked on? a navigable element such as an anchor, link or input?

Using 'find by value' may be a tad difficult if you don't know the value
to find by.
--
Rob


RobG,

Property? The nodeValue. For a text node element the text is stored in the
nodeValue property. I'm just trying to find a way to either get a
collection of only text nodes, so I can scan their nodeValue's, or anything
that saves me from traversing the whole DOM tree.

Thanks.
Aug 29 '05 #3

Robert Oschler wrote:
Property? The nodeValue. For a text node element the text is stored in the
nodeValue property. I'm just trying to find a way to either get a
collection of only text nodes, so I can scan their nodeValue's, or anything
that saves me from traversing the whole DOM tree.


Mozilla could do it using its XPath on HTML implementation, Mozilla and
Opera 8 should be able to do it using a TreeWalker, and Opera 8 also
implements NodeIterator
(<http://www.w3.org/TR/DOM-Level-2-Traversal-Range/traversal.html>). So
with those browsers you have options to look only at text nodes if needed.
IE does not have any W3C DOM Level 2 traversal but it has an
implementation of text searching within text ranges and then you can
expand the range to the parent element.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 29 '05 #4

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

Similar topics

2
by: Jürgen Holly | last post by:
Hi! I have the following xml-node: <docu> <p>Sample: <b>bold</b></p> <p>and text in <i>italic</i></p> </docu> I need to create a text-file, so I set the output-mode to text.
2
by: Martin | last post by:
Hallo, can you help me writing a generic xslt transformation (useable with xsql from oracle)? The problem is how to get the escaping characters .... === INPUT-File in.xml <?xml version =...
12
by: pillepop2003 | last post by:
Hey! Can anyone give me a hint, how this problem is best implemented: I have a table of users (see below), where every user has one "superior user" (= parent node), this should be a fully...
6
by: Ron Brennan | last post by:
I want if possible to use something like: element.getElementsByTagName('text') but that doesn't work. Is there another value for the parameter, or is it not possible with getElementsByTagName?...
5
by: Richard Lewis | last post by:
Hello Pythoners, I'm currently writing some Python to manipulate a semi-structured XML document. I'm using DOM (minidom) and I've got working code for transforming the document to HTML files and...
9
by: Bernd.Moos | last post by:
Given the following XML document: <text> <p> <w>Ronaldo</w> <w>scoredw> <w>the</w> <w>1</w> <c>:</c> <w>1</w>
2
by: RobG | last post by:
Why does Firefox insert #text nodes as children of TR elements? As a work-around for older Safari versions not properly supporting a table row's cells collection, I used the row's childNodes...
1
by: David Hirschfield | last post by:
I've written a tree-like data structure that stores arbitrary python objects. The objective was for the tree structure to allow any number of children per node, and any number of root nodes...and...
2
by: slizorn | last post by:
hi guys, i need to make a tree traversal algorithm that would help me search the tree.. creating a method to search a tree to find the position of node and to return its pointer value basically i...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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...
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.