简体   繁体   English

WSO2脚本中介者有效载荷附加子级

[英]WSO2 script mediator Payload append child

i'm using WSO2 ESB 4.8.1 and in particular way i'm facing up to script mediator. 我正在使用WSO2 ESB 4.8.1,尤其是我正视脚本中介者。 I need to resolve a doubt. 我需要解决一个疑问。 I need to build a payload made like this way: 我需要构建这样的有效负载:

<response>
    <urls>
        <url>http://myfirsturl</url>
        <url>http://mysecondurl</url>
        <url>>http://mythirdurl</url>
    </urls>
</response>

In my script mediator i wrote this snippet code: 在我的脚本中介器中,我编写了以下代码片段:

<script language="js">
        ...
        ...
        var clinvarPayload = <response><urls></urls></response>

        for (i = 0; i < myArray.length; ++i){
            clinvarPayload..*::urls.url = myArray[i]                  
        }          

        mc.setPayloadXML(clinvarPayload);

My problem is that after the end of the for loop i get the response containing just the last myArray element, ie: 我的问题是,在for循环结束后,我得到的响应仅包含最后一个myArray元素,即:

<response>
    <urls>
        <url>http://mythirdurl</url>            
    </urls>
</response>

What's wrong with my code? 我的代码有什么问题? How can i append the myArray elements? 我如何追加myArray元素?

You can use appendChild method to add a new node or += operator 您可以使用appendChild方法添加新节点或+ =运算符

See this : Modifying XML 请参见修改XML

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM