IBM JAVA节点更改默认名称空间前缀(NS1)

时间:2017-08-17 10:04:52

标签: xml xsd xml-namespaces ibm-integration-bus

我正在使用 IBM集成总线。当我没有声明任何名称空间时,它会向我的响应正文提供默认的NS1,如下所示:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <NS1:AvansEditResponse xmlns:NS1="http://Elma.sample.az">
     <Result>     
        <Error>
           <Exists>true</Exists>
           <ECode>E005</ECode>
           <EMessage>Avans editing error!</EMessage>
        </Error>
     </Result>
  </NS1:AvansEditResponse>

 

JAVA节点代码:

    MbOutputTerminal out = getOutputTerminal("out");
    MbOutputTerminal alt = getOutputTerminal("alternate");

    MbMessage inMessage = inAssembly.getMessage();
    MbMessage outMessage = new MbMessage();

    MbMessageAssembly outAssembly = new MbMessageAssembly(inAssembly, outMessage);
    MbElement outputBody = outAssembly.getMessage().getRootElement().createElementAsLastChild(MbXMLNSC.PARSER_NAME);

    OracleCallableStatement ostmt = null;

    //creating response element 
    MbElement responseMethod = outputBody.createElementAsLastChild(MbElement.TYPE_NAME, "AvansAddResponse", null);

    responseMethod.createElementAsLastChild(MbXMLNS.NAMESPACE_DECL, "e" ,Constants.ELMA_NAMESPACE);

    MbElement responseResult = responseMethod.createElementAsLastChild(MbElement.TYPE_NAME, "Result", null);

我想改变&#34; NS1:&#34;到&#34; e:&#34;。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

最后,我找到了解决方案。您可以使用以下代码添加前缀:

    MbElement vasDecl = response.createElementAsLastChild(MbXMLNSC.NAMESPACE_DECLARATION, "e", Constants.ELMA_NAMESPACE); 
    vasDecl.setNamespace("xmlns"); 
    response.setNamespace(Constants.ELMA_NAMESPACE);