title: Parse xml response using sax
body: <p>I have been following <a href="https://www.javacodegeeks.com/2012/01/xml-parsing-using-saxparser-with.html" rel="nofollow noreferrer">this</a> tutorial to use sax parser. If my input is using xml file, then the below line is working fine. But how can I can parse xml which I get as a response from the web service. How to pass soap response as input to sax parser?</p>
  
  <pre><code>new MySaxParser("catalog.xml");
  </code></pre>
  
  <p>My code</p>
  
  <pre><code>public class soapTest{
      private static SOAPMessage createSoapRequest() throws Exception{
           MessageFactory messageFactory = MessageFactory.newInstance();
           SOAPMessage soapMessage = messageFactory.createMessage();
           SOAPPart soapPart = soapMessage.getSOAPPart();
                   SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
                   soapEnvelope.addNamespaceDeclaration("action", "http://www.webserviceX.NET/");
           SOAPBody soapBody = soapEnvelope.getBody();
           SOAPElement soapElement = soapBody.addChildElement("GetQuote", "action");
           SOAPElement element1 = soapElement.addChildElement("symbol", "action");
           element1.addTextNode("ticket");
              MimeHeaders headers = soapMessage.getMimeHeaders();
              headers.addHeader("SOAPAction", "http://www.webserviceX.NET/GetQuote");
           soapMessage.saveChanges();
           System.out.println("----------SOAP Request------------");
           soapMessage.writeTo(System.out);
           return soapMessage;
       }
       private static void createSoapResponse(SOAPMessage soapResponse) throws Exception  {
          TransformerFactory transformerFactory = TransformerFactory.newInstance();
          Transformer transformer = transformerFactory.newTransformer();
          Source sourceContent = soapResponse.getSOAPPart().getContent();
          System.out.println("\n----------SOAP Response-----------");
          StreamResult result = new StreamResult(System.out);
          transformer.transform(sourceContent, result);
       }
       public static void main(String args[]){
              try{
              SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
              SOAPConnection soapConnection = soapConnectionFactory.createConnection();
              String url = "http://www.webservicex.net/stockquote.asmx?wsdl";
              SOAPMessage soapRequest = createSoapRequest();
              //hit soapRequest to the server to get response
              SOAPMessage soapResponse = soapConnection.call(soapRequest, url);
  
  // Not able to proceed from here. How to use sax parser here
  
          soapConnection.close();
  
          }catch (Exception e) {
               e.printStackTrace();
          }
  }
  </code></pre>
  
  <p>How to parse and get the value from xml response.</p>