Approach 1 is the best - then it'll make a List of
all the Text nodes and you can just index into the List if you like
List fragments =
root.selectNodes("text()")
Node node1 = (Node) fragments.get(0);
Node node2 = (Node) fragments.get(1);
String text1 = node1.getText();
String text2 = node2.getText(); Probably the fastest way though is just to iterate
through the content looking for Text nodes...
for (Iterator iter =
root.content().iterator(); iter.hasNext(); ) {
Node node =
(Node) iter.next();
if (node
instanceof Text) {
String
text = node.getText();
...
}
}
|
- [dom4j-user] Extracting Text Fragments Terry Steichen
- Re: [dom4j-user] Extracting Text Fragments Stephen C. Upton
- Re: [dom4j-user] Extracting Text Fragments James Strachan
- Fw: [dom4j-user] Extracting Text Fragments James Strachan
- Fw: [dom4j-user] Extracting Text Fragments Terry Steichen