// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.FileReader;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class ManualSoapParse {
    public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException {
         DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
         dbf.setNamespaceAware(false);
         DocumentBuilder db = dbf.newDocumentBuilder();
         Document doc = db.parse(new InputSource(new FileReader("/work/soap.xml")));
         XPath xpath = XPathFactory.newInstance().newXPath();
         Node n1 = (Node)xpath.evaluate("//Envelope/Body/CommandResponseData/CommandResult/TransactionResult/OperationResult/Operation[@name='operationname1']/ParameterList/StringParameter[@name='n1']/text()", doc.getDocumentElement(), XPathConstants.NODE);
         System.out.println(n1.getNodeValue());
         Node c1 = (Node)xpath.evaluate("//Envelope/Body/CommandResponseData/CommandResult/TransactionResult/OperationResult/Operation[@name='operationname2']/ParameterList/StringParameter[@name='c1']/text()", doc.getDocumentElement(), XPathConstants.NODE);
         System.out.println(c1.getNodeValue());
     }
}
