Hi Vikram,

Can you try the following Payload factory config?

<payloadFactory media-type="json">
            <format>{"Detail":"$1"}</format>
            <args>
               <arg evaluator="json" expression="$.Result.Detail"/>
            </args>
</payloadFactory>

Cheers,

*Nadeeshaan Gunasinghe*
Senior Software Engineer, WSO2 Inc. http://wso2.com
+94770596754 | [email protected] | Skype: nadeeshaan.gunasinghe <#>
<http://www.facebook.com/nadeeshaan.gunasinghe>
<http://lk.linkedin.com/in/nadeeshaan> <http://twitter.com/Nadeeshaan>
<http://nadeeshaan.blogspot.com/>
Get your own email signature
<https://wisestamp.com/email-install?utm_source=promotion&utm_medium=signature&utm_campaign=get_your_own>

On Mon, Jan 22, 2018 at 11:03 AM, Gihan Anuruddha <[email protected]> wrote:

> Have you tried something like this [1]? You need to add another XSLT
> processing after you get the original output.
>
> [1] - https://stackoverflow.com/questions/1571083/how-to-
> remove-root-element-from-xml-file
>
> Regards,
> Gihan
>
> On Mon, Jan 22, 2018 at 8:12 AM, Vinod Kavinda <[email protected]> wrote:
>
>> Hi Vikram,
>> This is happening because your XPath generates multiple elements with
>> below structure, which not your desired output.
>> *                        <Detail>*
>> * <a>26</a>*
>> * <b>box</b>*
>> * <c>2019-01-17T00:00:00</c>*
>> * </Detail> *
>>
>> In an XML point of view, you are expecting an xml content like below,
>> which is not a valid XML content since it does not have a root element. You
>> can test this with an online XPath evaluator and verify.
>>
>> *                         <Detail>*
>> * <a>40</a>*
>> * <b>car</b>*
>> * <c>2019-01-17T00:00:00</c>*
>> * </Detail>*
>> * <Detail>*
>> * <a>37</a>*
>> * <b>table</b>*
>> * <c>2019-01-17T00:00:00</c>*
>> * </Detail>*
>>
>>
>> I don't think you can achieve your requirement with the enrich mediator
>> since it only supports Xpaths. Please try using the Payload Factory
>> mediator[1] with Jsonpath. Then you can extract the "Detail" element from
>> the converted JSON and set it to the body.
>>
>> [1] - https://docs.wso2.com/display/EI611/PayloadFactory+Mediator
>>
>> On Sun, Jan 21, 2018 at 8:37 PM, vikram nayak <[email protected]>
>> wrote:
>>
>>>
>>>
>>> On Sunday, 21 January 2018 8:14 PM, vikram nayak <[email protected]>
>>> wrote:
>>>
>>>
>>> Hi All,,
>>>
>>> I have output like below from my xslt :
>>>
>>> <?xml version='1.0' encoding='utf-8'?>
>>> <soapenv:Envelope xmlns:soapenv="http://schemas.
>>> xmlsoap.org/soap/envelope/">
>>> <soapenv:Body>
>>> <Result>
>>> <Detail>
>>> <a>40</a>
>>> <b>car</b>
>>> <c>2019-01-17T00:00:00</c>
>>> </Detail>
>>> <Detail>
>>> <a>37</a>
>>> <b>table</b>
>>> <c>2019-01-17T00:00:00</c>
>>> </Detail>
>>> <Detail>
>>> <a>35</a>
>>> <b>book</b>
>>> <c>2019-01-17T00:00:00</c>
>>> </Detail>
>>> <Detail>
>>> <a>26</a>
>>> <b>box</b>
>>> <c>2019-01-17T00:00:00</c>
>>> </Detail>
>>> </Result>
>>> </soapenv:Body>
>>> </soapenv:Envelope>
>>>
>>> which gets converted into below json in postman :
>>>
>>> {
>>>     "Result": {
>>>         "Detail": [
>>>             {
>>>                 "a": "40",
>>>                 "b": "car",
>>>                 "c": "2019-01-17T00:00:00"
>>>             },
>>>             {
>>>                 "a": "37",
>>>                 "b": "table",
>>>                 "c": "2019-01-17T00:00:00"
>>>             },
>>>             {
>>>                 "a": "35",
>>>                 "b": "book",
>>>                 "c": "2019-01-17T00:00:00"
>>>             },
>>>             {
>>>                 "a": "26",
>>>                 "b": "box",
>>>                 "c": "2019-01-17T00:00:00"
>>>             }
>>>         ]
>>>     }
>>> }
>>>
>>> but in my desired output response . I do not want root element "Result".
>>>
>>> Desired output :
>>>
>>> {
>>>     "Detail": [
>>>             {
>>>                 "a": "40",
>>>                 "b": "car",
>>>                 "c": "2019-01-17T00:00:00"
>>>             },
>>>             {
>>>                 "a": "37",
>>>                 "b": "table",
>>>                 "c": "2019-01-17T00:00:00"
>>>             },
>>>             {
>>>                 "a": "35",
>>>                 "b": "book",
>>>                 "c": "2019-01-17T00:00:00"
>>>             },
>>>             {
>>>                 "a": "26",
>>>                 "b": "box",
>>>                 "c": "2019-01-17T00:00:00"
>>>             }
>>>         ]
>>>     }
>>> }
>>>
>>> Going through some online documents I tried below enrich after xslt.
>>>
>>> <enrich>
>>>     <source clone="true" xpath="$body/Result/Detail"/>
>>>     <target type="body"/>
>>> </enrich>
>>>
>>> But it gives only one element from my output  like below :
>>>
>>> {
>>>     "Detail": {
>>>         "insuranceNumber": "40",
>>>         "policyName": "Laptop insurance - 4 star",
>>>         "agreementValidTill": "2019-01-17T00:00:00"
>>>     }
>>> }
>>>
>>> Please guide.
>>>
>>> Thanks,
>>> Vikram
>>>
>>>
>>>
>>> _______________________________________________
>>> Dev mailing list
>>> [email protected]
>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>
>>>
>>
>>
>> --
>> Vinod Kavinda
>> Senior Software Engineer
>> *WSO2 Inc. - lean . enterprise . middleware <http://www.wso2.com>.*
>> Mobile : +94 (0) 712 415544
>> Blog : http://soatechflicks.blogspot.com/
>> [image: http://wso2.com/signature]
>> <http://wso2.com/signature>
>>
>>
>> _______________________________________________
>> Dev mailing list
>> [email protected]
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>
>
> --
> W.G. Gihan Anuruddha
> Associate Technical Lead | WSO2, Inc.
> M: +94772272595
>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to