Following is my xml:
<Body>
<tag1 xmlns=""> <innerTag></innerTag> </tag1>
</Body>
The problem is that I am not able to get the string inside <tag1></tag1>, that is <innerTag></innerTag>. Following is my logic:
public void startElement(final String uri, final String localName,
final String qName, final Attributes attributes)
throws SAXException {
if ("tag1".equalsIgnoreCase(qName)){
inTag1 = true;
System.out.println("start");
}
}
public void endElement(final String uri, final String localName,
final String qName) throws SAXException {
if ("tag1".equalsIgnoreCase(qName)) {
System.out.println("end");
inTag1 = false;
}
}
public void characters(final char[] ch, final int start, final int length) {
if (inTag1) {
System.out.println("@@@" + new String(ch, start, length));
}
}
}
But it is giving me empty output. Can anyone help.
innerTagis an element not a string or a text node. If you want to print it, you will have to do it in thestartElementandendElementcallback.<innerTag>will be dealt with bystartElement(and the closing tag byendElement, just printqnamein the else-part of your condition). So thecharactershandler won't see them.