I have an xml like this:
<Message xmlns="uri_of_message">
<VendorId>1234</VendorId>
<SequenceNumber>1</SequenceNumber>
...other important headers...
<Data>
<Functions xmlns="uri_of_functions_subxml">
<Function1 attr="sth">
<Info>Some_Info</Info>
</Function1>
<Function2>
<Info>Some_Info</Info>
</Function2>
...Functions n...
</Functions>
</Data>
</Message>
I need to extract inner xml
<Functions xmlns="uri_of_functions_subxml">
<Function1 attr="sth">
<Info>Some_Info</Info>
</Function1>
<Function2>
<Info>Some_Info</Info>
</Function2>
...Functions n...
</Functions>
I have firstly tried getting inner xml with characters method:
public void startElement(String uri, String localName, String tagName, Attributes attributes) throws SAXException {
if (tagName.equalsIgnoreCase("Data")){
buffer = new StringBuffer();}
}
public void characters(char[] ch, int start, int length) throws SAXException {
if (buffer != null) {
buffer.append(new String(ch, start, length).trim());
}
}
public void endElement(String uri, String localName, String tagName) throws SAXException {
if (tagName.equalsIgnoreCase("Data")){
innerXML = buffer.toString().trim();
}
But then i have realized that characters method haven't collected xml properly, it might have refused the special characters like "<", ">".
Link below contains same question but the answer is not applicable for me because the outer xml must be processed as sort of handshake signal, the inner xml must be processed in totally different way.
Java XML parsing: taking inner XML using SAX
Only thing that I need is to collect inner xml properly. But, how to do it? Thanks in advance..