Java 如何将前缀应用于SOAP消息中的所有子元素
在构造SOAP消息时,使用Java 如何将前缀应用于SOAP消息中的所有子元素,java,xml,web-services,dom,soap,Java,Xml,Web Services,Dom,Soap,在构造SOAP消息时,使用QName和javax.xml.SOAP.Name向ext:msg\u LocationDetails元素的子元素添加前缀时出现问题 我使用的是javax.xml.soap.SOAPFactory 当我尝试使用QName mag=newqname(“,”Messages“,”ext”) (新的QName(namespaceURI、localPart、前缀)) 下面是SOAP消息 <soapenv:Envelope xmlns:soapenv="http://sch
QName
和javax.xml.SOAP.Name向ext:msg\u LocationDetails
元素的子元素添加前缀时出现问题
我使用的是javax.xml.soap.SOAPFactory
当我尝试使用QName mag=newqname(“,”Messages“,”ext”)代码>
(新的QName(namespaceURI、localPart、前缀))
下面是SOAP消息
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ext="http://extdomain.com/">
<soapenv:Header/>
<soapenv:Body>
<ext:msg_LocationDetails>
<ext:Messages>
<ext:Message>
<ext:Location>GSA</ext:Location>
<ext:LocCode>Unit</ext:LocCode>
<ext:LocID>00004</ext:LocID>
<ext:SystemID>TSKSLSLSJJ</ext:SystemID>
<ext:Status>
<ext:ID>4</ext:ID>
<ext:Name>PENDING</ext:Name>
</ext:Status>
</ext:Message>
</ext:Messages>
</ext:msg_LocationDetails>
</soapenv:Header/>
</soapenv:Body>
GSA
单位
00004
tskslsjj
4.
悬而未决的
为什么要将空字符串作为QName
构造函数中的第一个参数传递?根据XML示例,名称空间URI应该是http://extdomain.com/
。根据需要生成的消息,我在子元素中不需要它。
SOAPBody soapBody = soapEnvelope.getBody();
soapBody = soapMessage.getSOAPBody();
soapBody.setPrefix("soapenv");
// To add some element
SOAPFactory soapFactory = SOAPFactory.newInstance();
Name bodyName = soapFactory.createName("msg_LocationDetails");
SOAPBodyElement locationDetails = soapBody.addBodyElement(bodyName);
locationDetails.setPrefix("ext");
QName mag = new QName("","Messages","ext");
SOAPElement messages = locationDetails.addChildElement(mag);
//SOAPElement messages = locationDetails.addChildElement("Messages");
//messages.addNamespaceDeclaration("fir", "");
//SOAPElement message = messages.addChildElement("message");
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ext="http://extdomain.com/">
<soapenv:Header/>
<soapenv:Body>
<ext:msg_LocationDetails>
<ext:Messages>
<ext:Message>
<ext:Location>GSA</ext:Location>
<ext:LocCode>Unit</ext:LocCode>
<ext:LocID>00004</ext:LocID>
<ext:SystemID>TSKSLSLSJJ</ext:SystemID>
<ext:Status>
<ext:ID>4</ext:ID>
<ext:Name>PENDING</ext:Name>
</ext:Status>
</ext:Message>
</ext:Messages>
</ext:msg_LocationDetails>
</soapenv:Header/>
</soapenv:Body>