SOAP メッセージを生成できますが、わかりません
soapMessage タグにのみプレフィックスを追加します (名前空間を持たないでください)
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = soapConnectionFactory.createConnection(); SOAPFactory soapFactory = SOAPFactory.newInstance(); MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); SOAPMessage message = factory.createMessage(); SOAPHeader header = message.getSOAPHeader(); SOAPPart soapPart = message.getSOAPPart(); SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); SOAPBody body = soapEnvelope.getBody(); soapEnvelope.removeNamespaceDeclaration(soapEnvelope.getPrefix()); soapEnvelope.setPrefix("soap"); body.setPrefix("soap"); header.removeNamespaceDeclaration(header.getPrefix()); header.setPrefix("soap"); soapEnvelope.addNamespaceDeclaration("v9", "URL TO SERVER"); Name bodyName; bodyName = soapFactory.createName("SearchHotels"); SOAPBodyElement getList = body.addBodyElement(bodyName); getList.setPrefix("v9"); Name childName = soapFactory.createName("SoapMessage", "v9", "URL TO SERVER"); SOAPElement HotelListRequest = getList.addChildElement(childName); HotelListRequest.addChildElement("Hotel", "v9").addTextNode("Hilton");
私の SOAP メッセージ
...
<v9:SoapMessage xmlns:els="URL TO SERVER">
...
私が期待すること
...
<v9:SoapMessage>
...
アップデート :
以下を使用すると、次のエラーが発生します
SOAPElement HotelListRequest = getList.addChildElement("v9:SoapMessage");
org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a
way which is incorrect with regard to namespaces.