Jaxb 解组任何类型的 xml 文档

沙达布

我有一个服务方法,它有一个带有 2 个参数的方法:

    public int ReadXmlDocAsString(@WebParam(name = "password") String password, 
                                  @WebParam(name = "doc") com.vincari.hl7.jaxws.xmlDoc<Object> doc){

    }

我的 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;
}   
}

我的示例肥皂请求是:

<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>

我能够使用 cxf 部署网络服务。但是当我尝试映射 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 将其映射到字符串。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章