Extracting Text Nodes From XML File Using SAX Parser in JAVA?

Here's some pseudo-code: private boolean insideElementContainingTextNode; private StringBuilder textBuilder; public void startElement(String uri, String localName, String qName, Attributes attrs) { if ("w:t". Equals(qName)) { // or is it localName? InsideElementContainingTextNode = true; textBuilder = new StringBuilder(); } } public void characters(char ch, int start, int length) { if (insideElementContainingTextNode) { textBuilder.

Append(ch, start, length); } } public void endElement(String uri, String localName, String qName) { if ("w:t". Equals(qName)) { // or is it localName? InsideElementContainingTextNode = false; String theCompleteText = this.textBuilder.toString(); this.

TextBuilder = null; } }.

Hmm, I tried that, but it didn't extract any text. Can you explain what that code is supposed to do? – This 0ne Pr0grammer Jun 29 at 22:07 In startElement, you check if the parser starts reading the element containing the text node you want to extract.

If yes, you set a boolean variable to true. This way, the characters method knows that it's inside the appropriate element, and it stores the read text inside a StringBuilder. The method endElement is called when the end of the element is reached.

You can thus get the contents of the StringBuilder and store it whereever you want. I only stored it in a local variable (theCompleteText), but you may store it in an instance variable if you need to. – JB Nizet Jun 30 at 7:09.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions