【问题标题】:IBM JAVA node change default namespace prefix (NS1)IBM JAVA 节点更改默认名称空间前缀 (NS1)
【发布时间】:2021-11-20 11:15:11
【问题描述】:

我正在使用 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:”。我该怎么做?

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-21
        • 2021-03-22
        • 1970-01-01
        相关资源
        最近更新 更多