0
나는 sax 파서를 사용하는 this 자습서를 따라 왔습니다. 내 입력 XML 파일을 사용하는 경우 다음 줄 아래에 잘 작동합니다. 하지만 웹 서비스의 응답으로 얻을 수있는 xml을 어떻게 파싱 할 수 있습니까? 어떻게 sax 파서에 입력으로 비누 응답을 전달할 수 있습니까?색소폰을 사용하여 XML 응답을 구문 분석
new MySaxParser("catalog.xml");
내 코드
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();
}
}
분석하고 XML 응답에서 값을 얻는 방법.
덕분에 내 문제를 조사합니다. 비누 응답을 스트리밍 할 수 있지만 코드가 어딘가에 매달려 있습니다. 당신은 내 문제를 알기 위해 아래의 게시물을 읽을 수있다. http://stackoverflow.com/questions/42210300/stream-soap-response-and-parse-using-sax-parser – user4324324
나는 코드를 스케치 한 것처럼 보이지만 스트림을 생략했다. 양조에서 폐쇄, 나는 게시물을 수정합니다 (예외를 던지지 말고, 잡아야하며, 스트림을 잡아야합니다.) 그럼 당신의 '매달려'는 아마 –
사라지고 나 자신을 속이고, 더 나쁜 것은 당신도 이것을 볼 수 있습니다 : http://stackoverflow.com/questions/484119/why-doesnt-more-java-code- use-pipedinputstream-pipedoutputstream –