How to get some xml that comes before and a little from after a DOM Node.
Posted
by startoftext
on Stack Overflow
See other posts from Stack Overflow
or by startoftext
Published on 2010-04-09T15:41:08Z
Indexed on
2010/04/09
15:43 UTC
Read the original article
Hit count: 300
I am using java and I am pretty open to using w3c DOM or DOM4J at this point.
So lets say I have a Node like a text node that I have found something interesting in, like say an occurrence of a substring in the nodes text. If I want to get a string with a number characters preceding that node and a few characters after that node how may I do that? Basically I need to be able to display a snippet of the original xml around the occurrence of that string.
The problem I have with getting the parent node for example and then calling asXML is that I no longer know the exact location of the substring in the text node. If I search again for that string value in the parents xml then I may find 2 occurrences or many more if the parent has other children that contain an occurrence of that string.
Much appreciation if any one can answer this question.
© Stack Overflow or respective owner