my app is to find a given input string in a html file and then set its background colour to yellow.
I've created a visitor and am able to find the TextNodes of input string right fine.
the alogrithm for turning on the background I thought would be:
for each TextNode (that forms a part of the input string)
split the text into: "before", "belongs to", "after" the part that belongs to the input string.
for each "belongs to"
create a new span as its new parent
set the background colour
set the parent of the span to the original parent of the "belongs to"
the problem I've having is that for text wrapped in a <b> tag the parent of the TextNode is not the <b> but the <span> that is the parent of the <b>.
for the ex.: <span id="p3_10"><br><b id="p3_12">Thursday August 30, 2007</b></span>
the result of:
Node parentNode = ((TextNode)n).getParent();
String id = ((Tag)parentNode).getAttribute("id");
is:
TEXT i = 50 Thursday August 30, 2007
PARENT IS A TAG i = 50 PARENT ID = p3_10 PARENT NAME = SPAN
TAG i = 51 B
PARENT IS A TAG i = 51 PARENT ID = p3_10 PARENT NAME = SPAN
in javascript the parent of the text is recognized as the <b> tag.
I was wondering if you had any suggestions as to obtaining recognition of the immediate parent or if that is not possible a work around.
thank you for any assistance that you might be able to provide
Brian
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
my app is to find a given input string in a html file and then set its background colour to yellow.
I've created a visitor and am able to find the TextNodes of input string right fine.
the alogrithm for turning on the background I thought would be:
for each TextNode (that forms a part of the input string)
split the text into: "before", "belongs to", "after" the part that belongs to the input string.
for each "belongs to"
create a new span as its new parent
set the background colour
set the parent of the span to the original parent of the "belongs to"
the problem I've having is that for text wrapped in a <b> tag the parent of the TextNode is not the <b> but the <span> that is the parent of the <b>.
for the ex.: <span id="p3_10"><br><b id="p3_12">Thursday August 30, 2007</b></span>
the result of:
Node parentNode = ((TextNode)n).getParent();
String id = ((Tag)parentNode).getAttribute("id");
is:
TEXT i = 50 Thursday August 30, 2007
PARENT IS A TAG i = 50 PARENT ID = p3_10 PARENT NAME = SPAN
TAG i = 51 B
PARENT IS A TAG i = 51 PARENT ID = p3_10 PARENT NAME = SPAN
in javascript the parent of the text is recognized as the <b> tag.
I was wondering if you had any suggestions as to obtaining recognition of the immediate parent or if that is not possible a work around.
thank you for any assistance that you might be able to provide
Brian
Hi there,
an addendum:
the TextNode "Thursday ... " is listed among the children of the <span> tag,
the <br> tag and the <b> tag.
thank you again,
Brian
The FAQ article http://htmlparser.sourceforge.net/faq.html#composite shows how to make <B> tags composite so that it will have the text nested inside it.
Or failing that, try walking backwards up the children list from the text node of interest, looking for TagNode objects with an ID attribute.