从CXF响应中删除XML节点

时间:2016-03-23 15:14:56

标签: java xml cxf

我希望从我从网络服务获取的XML响应中删除节点。我试图通过使用StaxTransformFeature来完成此操作,但是却无法删除响应的ns1:ivrOrderRequest0Response节点。

    final StaxTransformFeature feature = new StaxTransformFeature();
    feature.setInDropElements(Collections.singletonList("ns1:ivrOrderRequest0Response"));
    feature.initialize(client, client.getBus());

我正在处理的XML是:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <ns1:ivrOrderRequest0Response xmlns:ns1="http://type.webservice.net/" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
      <ivrOrderRequest0Return href="#id0"/>
    </ns1:ivrOrderRequest0Response>
    <multiRef xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://type.ivrwebservice.net" id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:IVRReturn">
      <DCRIS_RC xsi:type="xsd:string">0326</DCRIS_RC>
      <DCRIS_Return_Description xsi:type="xsd:string">NUMBER-DIRECT RECORD NOT FOUND</DCRIS_Return_Description>
      <dcrisRec1 xsi:type="xsd:string" xsi:nil="true"/>
      <dcrisRec10 xsi:type="xsd:string" xsi:nil="true"/>
      <dcrisRec2 xsi:type="xsd:string" xsi:nil="true"/>
      <dcrisRec3 xsi:type="xsd:string" xsi:nil="true"/>
      <dcrisRec4 xsi:type="xsd:string" xsi:nil="true"/>
      <dcrisRec5 xsi:type="xsd:string" xsi:nil="true"/>
      <dcrisRec6 xsi:type="xsd:string" xsi:nil="true"/>
      <dcrisRec7 xsi:type="xsd:string" xsi:nil="true"/>
      <dcrisRec8 xsi:type="xsd:string" xsi:nil="true"/>
      <dcrisRec9 xsi:type="xsd:string" xsi:nil="true"/>
      <telephoneNumber xsi:type="xsd:string">4024642151</telephoneNumber>
    </multiRef>
  </soapenv:Body>
</soapenv:Envelope>

所需的结果是:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
      <ivrOrderRequest0Return href="#id0"/>
    <multiRef xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://type.ivrwebservice.net" id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:IVRReturn">
      <DCRIS_RC xsi:type="xsd:string">0326</DCRIS_RC>
      <DCRIS_Return_Description xsi:type="xsd:string">NUMBER-DIRECT RECORD NOT FOUND</DCRIS_Return_Description>
      <dcrisRec1 xsi:type="xsd:string" xsi:nil="true"/>
      <dcrisRec10 xsi:type="xsd:string" xsi:nil="true"/>
      <dcrisRec2 xsi:type="xsd:string" xsi:nil="true"/>
      <dcrisRec3 xsi:type="xsd:string" xsi:nil="true"/>
      <dcrisRec4 xsi:type="xsd:string" xsi:nil="true"/>
      <dcrisRec5 xsi:type="xsd:string" xsi:nil="true"/>
      <dcrisRec6 xsi:type="xsd:string" xsi:nil="true"/>
      <dcrisRec7 xsi:type="xsd:string" xsi:nil="true"/>
      <dcrisRec8 xsi:type="xsd:string" xsi:nil="true"/>
      <dcrisRec9 xsi:type="xsd:string" xsi:nil="true"/>
      <telephoneNumber xsi:type="xsd:string">4024642151</telephoneNumber>
    </multiRef>
  </soapenv:Body>
</soapenv:Envelope>

如果有人有这方面的帮助,我们将不胜感激!

0 个答案:

没有答案