I need to parse HL7 message ,firstly ,validate the message and then parse.
XMLParser xmlParser = new DefaultXMLParser();
//encode message in XML
String hl7MessageInXML = null;
try {
hl7MessageInXML = xmlParser.encode(message);
} catch (HL7Exception e) {
e.printStackTrace();
}
Try using HAPI Parser api (http://hl7api.sourceforge.net/). Here you can find some examples about parsing HL7 messages:
http://ignaciosuay.com/how-to-use-hapi-terser-with-hl7/
http://ignaciosuay.com/how-to-set-repetitions-in-hl7-messages-using-hapi-terser/
Hope it helps
Example code: