RE: [Htmlparser-developer] Label Tag
Brought to you by:
derrickoswald
|
From: <dha...@or...> - 2003-05-01 11:18:34
|
Hi Somik,
The mechanism suggested by you to replace the node is not working. I am
attaching a piece of code I wrote in LabelScannerTest to test the same.
public void testSettingLabels() throws ParserException {
createParser("<label><span>Jane <b> Doe </b>
Smith</span></label>");
parser.registerScanners();
LabelScanner labelScanner = new LabelScanner("-l");
parser.addScanner(labelScanner);
parseAndAssertNodeCount(1);
assertTrue(node[0] instanceof LabelTag);
LabelTag labelTag = (LabelTag) node[0];
assertStringEquals("Label","<LABEL><SPAN>Jane <B> Doe </B>
Smith</SPAN></LABEL>",labelTag.toHtml());
Node [] nodeArray = labelTag.getChildrenAsNodeArray();
StringNode node = new StringNode(new StringBuffer("New
Label"), 0, 0);
nodeArray[0] = node;
for(int i=1;i<nodeArray.length;i++)
{
nodeArray[i] = null;
}
assertEquals("Label value","New
Label",labelTag.getChildrenHTML());
assertEquals("Label value","New Label",labelTag.getLabel());
assertStringEquals("Label","<LABEL>New
Label</LABEL>",labelTag.toHtml());
}
Regards,
Dhaval Udani
Senior Analyst
M-Line, QPEG
OrbiTech Solutions Ltd.
+91-22-28290019 Extn. 1457
-----Original Message-----
From: somik [mailto:so...@ya...]
Sent: Thursday, May 01, 2003 4:27 AM
To: htmlparser-developer
Cc: somik
Subject: RE: [Htmlparser-developer] Label Tag
--- dha...@or... wrote:
> Thanx a lot. Exactly what I needed. Pretty stupid of
> me to ask ont eh
> forum actually. Should have searched the javadocs
> first. Sorry about it.
> Will try to make sure that it does not happen again.
No, sorry wont do - you have to copy 10 essays (or
programs) in detention :). Chill out!
> I was thinking of a setLabel wherein the user would
> give a single string
> (it might have many tags). Internally, setLabel()
> would parse it into
> its corresponding tags and assign it as the children
> of the Label tag.
> What do you guys think? Lemme know.
That would work - but would be costly (in
performance). You really dont want to rig up an
internal parser just to change the label tag data.
A simpler way is to find out which string node you
wish to change (digupStringNode(), searchFor(), or
quite simply, the exact index which you might happen
to know).
Then,
StringNode newNode = new StringNode(
newDataBuffer, 0, 0
);
To replace the child, you can either do something as
simple as,
getChildrenAsNodeArray()[posOfOldNode] = newNode;
or
NodeList nodeList = getChildren();
and make a similar modification in the nodelist.
Regards,
Somik
__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Htmlparser-developer mailing list
Htm...@li...
https://lists.sourceforge.net/lists/listinfo/htmlparser-developer
|