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

IBM JAVA node change default namespace prefix (NS1)

我正在使用 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);

我想将 "NS1:" 更改为 "e:"。我该怎么做?

终于,我找到了解决办法。您可以使用以下代码添加前缀:

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

我明白了,我没有使用那个 Constants 对象,而是把我的命名空间放在:

MbElement vasDecl = response.createElementAsLastChild(MbXMLNSC.NAMESPACE_DECLARATION, "e", "http://here-my-namespace.com");
vasDecl.setNamespace("xmlns");