2017-07-21 11 views
1

JAXBアンマーシャリングのXML文書ANYTYPE

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要求は、次のように

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

    } 

マイXMLDOCクラスは次のとおりです。

<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を使用してWebサービスを展開できます。しかし、私はdocオブジェクトをマップしようとし、文字列として取得しようとします。私はtoStringを使い、DOMSourceを使って変換しようとしました。これをどのように文字列に変換できますか?どんな助けでも大歓迎です。

答えて

1
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を使用して文字列にマップする必要があります。

関連する問題