Java Jaxb将xml文档反编组为任意类型
我有一个服务方法,该方法有两个参数:Java Jaxb将xml文档反编组为任意类型,java,web-services,jaxb,cxf,marshalling,Java,Web Services,Jaxb,Cxf,Marshalling,我有一个服务方法,该方法有两个参数: public int ReadXmlDocAsString(@WebParam(name = "password") String password, @WebParam(name = "doc") com.vincari.hl7.jaxws.xmlDoc<Object> doc){ } public int ReadXmlDocAsString(@WebP
public int ReadXmlDocAsString(@WebParam(name = "password") String password,
@WebParam(name = "doc") com.vincari.hl7.jaxws.xmlDoc<Object> doc){
}
public int ReadXmlDocAsString(@WebParam(name=“password”)字符串密码,
@WebParam(name=“doc”)com.vincari.hl7.jaxws.xmlDoc){
}
我的xmlDoc类如下所示:
public class xmlDoc<T> {
@XmlMixed
@XmlAnyElement(lax = true)
protected List<T> content;
public List<T> getContent() {
if (content == null) {
content = new ArrayList<T>();
}
return this.content;
}
public void setContent() {
content = this.content;
}
}
公共类xmlDoc{
@混合
@xmlanyement(lax=true)
受保护的列表内容;
公共列表getContent(){
if(content==null){
content=newarraylist();
}
返回此.content;
}
公共内容{
content=this.content;
}
}
我的soap请求示例是:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:sample="http://sample.vincari.com/">
<soap:Header/>
<soap:Body>
<sample:ReadXmlDocAsString>
<!--Optional:-->
<password>1234</password>
<!--Zero or more repetitions:-->
<doc>
<Header Application="SourceApp">
<CustomerData>
<Customer AccountNumber="1234" customername="ABCD">
</Customer>
<CustomerData>
</Header>
</doc>
</sample:InsertPatientInfoImpl>
</soap:Body>
</soap:Envelope>
1234
我能够使用cxf部署Web服务。但是当我尝试映射doc对象并尝试将其作为字符串获取时。我使用toString并尝试使用DOMSource进行转换。如何将其转换为字符串。非常感谢您的帮助
Document inputDoc = ((Element) doc.getContent().get(0)).getOwnerDocument();
String inputPayload = "";
StringWriter sw = new StringWriter();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.transform(new DOMSource(inputDoc), new StreamResult(sw));
inputPayload = sw.toString();
System.out.println("Read the input stream successfully "+ inputPayload);
当您在wsdl参数中使用anytype进行映射时。它将映射到列表或其他集合,然后我们需要使用DOM将其映射到字符串