title: Parse SOAP Message using STAX
body: <p>I have written the following code to Parse SOAP message using STAX. I am getting null pointer exception at xmlStreamReader.hasNext(). Please help.</p>
  
  <pre><code>    Source src = soapMsg.getSOAPPart().getContent();
      ...
      HorizonHeaderData header = parser.parseHorizonHeader(src);
      ...
      public HorizonHeaderData parseHorizonHeader(Source src) {
      HorizonHeaderData header = new HorizonHeaderData();
      XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
      if (null != src) {
  
          try {
              XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(src);
  
  
              if(xmlStreamReader==null){
                  System.out.println("xmlStreamReader is null");
              }
  
              while(xmlStreamReader.hasNext()){
                  int event = xmlStreamReader.getEventType();
                  switch(event){
                  case XMLStreamConstants.START_ELEMENT:
                          System.out.println("Element: "+ xmlStreamReader.getLocalName() + "\nValue: "+ xmlStreamReader.getElementText());
                  }
  
                  xmlStreamReader.next();
  </code></pre>
  
  <p>The input XML is </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bpel="http://xmlns.oracle.com/TestLoggingComposite/SSNService/BPELProcess2"&gt;
     &lt;soapenv:Header&gt;
      &lt;oas:Security soapenv:mustUnderstand="0" xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:soap="soap" xmlns:xsi="xsi"&gt;
           &lt;wsu:SecurityContextToken xmlns:wsu="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512"&gt;
              &lt;wsu:Identifier&gt;${=java.util.UUID.randomUUID()}&lt;/wsu:Identifier&gt;
           &lt;/wsu:SecurityContextToken&gt;
        &lt;/oas:Security&gt;
     &lt;/soapenv:Header&gt;
     &lt;soapenv:Body/&gt;
  &lt;/soapenv:Envelope&gt; </code></pre>
  </div>
  </div>
  </p>
  
  <p>I am able see the values using DOM but there is exception using STAX. Kindly help.</p>