Hi Buddhima,

one more concern, your solutoin fails when an xml tag in the middle (not
the last) is empty, it works fine only when the last xml tag is emty. the
tostring method call fails
  Cannot call method "toString" of undefined (<Unknown Source>#5)

when an xml tag which is not the last one is set with no value.

regards
Awanthika

On Thu, Feb 5, 2015 at 7:58 AM, Awanthika Senarath <[email protected]>
wrote:

> Thanks Buddhima,
>
> your solution worked!
>
> regards
> Awanthika
>
> On Thu, Feb 5, 2015 at 12:56 AM, Malaka Silva <[email protected]> wrote:
>
>> You can also try [1]
>>
>> [1]
>> http://mrmalakasilva.blogspot.co.uk/2014/03/how-to-remove-xml-elements-using-script.html
>>
>> On Wed, Feb 4, 2015 at 6:01 PM, Buddhima Wijeweera <[email protected]>
>> wrote:
>>
>>> Hi,
>>>
>>> Following script will do the job:
>>>
>>> <script language="js">
>>> var fullContent =  mc.getPayloadXML();
>>> for(var index in  fullContent..*::advancedImageSearchVO.children()){
>>>
>>>
>>>     var b = fullContent..*::advancedImageSearchVO.children()[index];
>>>
>>>
>>>
>>>
>>>            if(b.toString() ==''){
>>>      delete fullContent..*::advancedImageSearchVO.children()[index];
>>>    }
>>>
>>>      }
>>>    mc.setPayloadXML(fullContent);
>>>
>>> </script>
>>>
>>> Thanks!
>>>
>>>
>>> On Wed, Feb 4, 2015 at 2:50 PM, Awanthika Senarath <[email protected]>
>>> wrote:
>>>
>>>>
>>>> Hi,
>>>>
>>>> in trying to do $subject, i am using the script mediator as folows
>>>>
>>>> * <script language="js">*
>>>>
>>>> *var fullContent =  mc.getPayloadXML();  *
>>>> *var entity = mc.getPayloadXML()..*::entity;*
>>>>
>>>> *if (entity==null){*
>>>> *      fullContent.removeChild(entity);*
>>>> *   } *
>>>>
>>>> *mc.setPayloadXML(fullContent);*
>>>>
>>>> *</script>*
>>>>
>>>>
>>>> but my output always contains the empty tag <entity>
>>>>
>>>> sample xml output received
>>>>
>>>> Envelope:
>>>> <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="
>>>> http://www.w3.org/2003/05/soap-envelope";>
>>>> <soapenv:Body>
>>>> <ejb:getAdvancedDocumentReferenceList xmlns:ejb="
>>>> http://ejb.image.pfpc.com"; xmlns:vo="http://vo.image.pfpc.com";>
>>>> <ejb:provider>myProvidor</ejb:provider>
>>>>
>>>> <ejb:advancedImageSearchVO>
>>>>
>>>> <vo:departmentID>myID</vo:departmentID>
>>>> <vo:entity></vo:entity>         <--------- empty xml tag with no
>>>> content
>>>>
>>>> </ejb:advancedImageSearchVO>
>>>>
>>>> </ejb:getAdvancedDocumentReferenceList>
>>>> </soapenv:Body>
>>>> </soapenv:Envelope>
>>>>
>>>>
>>>> where as the expected output shoud be
>>>>
>>>>
>>>> Envelope:
>>>> <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="
>>>> http://www.w3.org/2003/05/soap-envelope";>
>>>> <soapenv:Body>
>>>> <ejb:getAdvancedDocumentReferenceList xmlns:ejb="
>>>> http://ejb.image.pfpc.com"; xmlns:vo="http://vo.image.pfpc.com";>
>>>> <ejb:provider>myProvidor</ejb:provider>
>>>>
>>>> <ejb:advancedImageSearchVO>
>>>>
>>>> <vo:departmentID>myID</vo:departmentID>
>>>>
>>>>
>>>> </ejb:advancedImageSearchVO>
>>>>
>>>> </ejb:getAdvancedDocumentReferenceList>
>>>> </soapenv:Body>
>>>> </soapenv:Envelope>
>>>>
>>>>
>>>>
>>>> can someone point out what I am doing wrong?
>>>>
>>>>
>>>> --
>>>> Awanthika Senarath
>>>> Software Engineer, WSO2 Inc.
>>>> Mobile: +94717681791
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Buddhima Wijeweera
>>> Software Engineer; WSO2 Inc.; http://wso2.com ,
>>>
>>> Mobile: +94 71 427 9966
>>> Email: [email protected]
>>> Blog:   https://buddhimawijeweera.wordpress.com
>>> GitHub Profile: https://github.com/Buddhima
>>>
>>> _______________________________________________
>>> Dev mailing list
>>> [email protected]
>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>
>>>
>>
>>
>> --
>>
>> Best Regards,
>>
>> Malaka Silva
>> Senior Tech Lead
>> M: +94 777 219 791
>> Tel : 94 11 214 5345
>> Fax :94 11 2145300
>> Skype : malaka.sampath.silva
>> LinkedIn : http://www.linkedin.com/pub/malaka-silva/6/33/77
>> Blog : http://mrmalakasilva.blogspot.com/
>>
>> WSO2, Inc.
>> lean . enterprise . middleware
>> http://www.wso2.com/
>> http://www.wso2.com/about/team/malaka-silva/
>> <http://wso2.com/about/team/malaka-silva/>
>>
>> Save a tree -Conserve nature & Save the world for your future. Print this
>> email only if it is absolutely necessary.
>>
>
>
>
> --
> Awanthika Senarath
> Software Engineer, WSO2 Inc.
> Mobile: +94717681791
>
>
>


-- 
Awanthika Senarath
Software Engineer, WSO2 Inc.
Mobile: +94717681791
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to