I would like to extract all text elements that display directly as a child node for the root node . I took a look at the standard java sax features using DefaultHandler; but that doesn't seem to be the way to go.
The problem is getting the first-level onlynodes, not just extracting the text nodes .
Is there any non-DOM based approach for this? (Note that node names are not known in advance)
[EDIT]
Input example
<root>
<a>text1</a>
<b>text2</b>
<c>text3</c>
<nested>
<d>not_text4</d>
...
<nested>
...
</root>
Sample output
Map<String, String> map := {
{a, text1}
{b, text2}
{c, text3}
}
It is currently being addressed as a DOM-oriented method. Although there are libraries that offer a subset of xpath expressions for SAX / STAX.