简体   繁体   中英

How can I remove brackets from payload in mule ESB?

Currently I have a payload with brackets and with a , to separate each of the rows. The idea is to remove the [ at the beginning and the ] at the end, as well as , in the middle

Are there any idea?

[<?xml version="1.0" encoding="UTF-8"?><reserveCPE_Res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><reserveCPE_Res_Part><t_reserve_res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1" class="R"><T_SUCCESS_FLAG>N</T_SUCCESS_FLAG><ORDER_NO/><DESCR2000>Not available. (30000,8)</DESCR2000><t_reserve_array class="R"><T_CPE_TYPE>SDSTB</T_CPE_TYPE><T_CPE_MODEL/><T_CPE_TYPE_QTY>0</T_CPE_TYPE_QTY></t_reserve_array><t_reserve_array class="R"><T_CPE_TYPE>SDSTB</T_CPE_TYPE><T_CPE_MODEL/><T_CPE_TYPE_QTY>0</T_CPE_TYPE_QTY></t_reserve_array></t_reserve_res></reserveCPE_Res_Part></reserveCPE_Res>, <?xml version="1.0" encoding="UTF-8"?><reserveCPE_Res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><reserveCPE_Res_Part><t_reserve_res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1" class="R"><T_SUCCESS_FLAG>N</T_SUCCESS_FLAG><ORDER_NO/><DESCR2000>The Business Unit MARIO is not exist. (30000,4)</DESCR2000></t_reserve_res></reserveCPE_Res_Part></reserveCPE_Res>, <?xml version="1.0" encoding="UTF-8"?><reserveCPE_Res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><reserveCPE_Res_Part><t_reserve_res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1" class="R"><T_SUCCESS_FLAG>N</T_SUCCESS_FLAG><ORDER_NO/><DESCR2000>The Business Unit ERNES is not exist. (30000,4)</DESCR2000></t_reserve_res></reserveCPE_Res_Part></reserveCPE_Res>]

my comment is too long to be posted in comment section so rather posting here.

this is how your payload is looking.

[<?xml version="1.0" encoding="UTF-8"?>
<reserveCPE_Res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <reserveCPE_Res_Part>
        <t_reserve_res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1" class="R">
            <T_SUCCESS_FLAG>N</T_SUCCESS_FLAG>
            <ORDER_NO/>
            <DESCR2000>Not available. (30000,8)</DESCR2000>
            <t_reserve_array class="R">
                <T_CPE_TYPE>SDSTB</T_CPE_TYPE>
                <T_CPE_MODEL/>
                <T_CPE_TYPE_QTY>0</T_CPE_TYPE_QTY>
            </t_reserve_array>
            <t_reserve_array class="R">
                <T_CPE_TYPE>SDSTB</T_CPE_TYPE>
                <T_CPE_MODEL/>
                <T_CPE_TYPE_QTY>0</T_CPE_TYPE_QTY>
            </t_reserve_array>
        </t_reserve_res>
    </reserveCPE_Res_Part>
</reserveCPE_Res>, <?xml version="1.0" encoding="UTF-8"?>
<reserveCPE_Res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <reserveCPE_Res_Part>
        <t_reserve_res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1" class="R">
            <T_SUCCESS_FLAG>N</T_SUCCESS_FLAG>
            <ORDER_NO/>
            <DESCR2000>The Business Unit MARIO is not exist. (30000,4)</DESCR2000>
        </t_reserve_res>
    </reserveCPE_Res_Part>
</reserveCPE_Res>, <?xml version="1.0" encoding="UTF-8"?>
<reserveCPE_Res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <reserveCPE_Res_Part>
        <t_reserve_res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1" class="R">
            <T_SUCCESS_FLAG>N</T_SUCCESS_FLAG>
            <ORDER_NO/>
            <DESCR2000>The Business Unit ERNES is not exist. (30000,4)</DESCR2000>
        </t_reserve_res>
    </reserveCPE_Res_Part>
</reserveCPE_Res>]

after every comma there is a new xml that start, so you cannot embed multiple xml's under one xml unless what you are trying is to have multiple rows of data in xml.

the first thing that you want to do is to convert your input into a well-formed XML currently it is not. look at all these , <?xml version="1.0" encoding="UTF-8"?> in your payload makes it junk.

the following code will do what you are looking for

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
    <file:connector name="File" outputPattern="*" writeToDirectory="C:\Temp" readFromDirectory="C:\Users\satichen\Desktop\work\test" workDirectory="C:\Users\satichen\Desktop\saruku" autoDelete="false" streaming="true" validateConnections="true" doc:name="File"/>
    <http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration"/>
    <flow name="playgroundFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
        <set-payload value="#['[&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;reserveCPE_Res xmlns=&quot;http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1&quot; xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;&lt;reserveCPE_Res_Part&gt;&lt;t_reserve_res xmlns=&quot;http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1&quot; class=&quot;R&quot;&gt;&lt;T_SUCCESS_FLAG&gt;N&lt;/T_SUCCESS_FLAG&gt;&lt;ORDER_NO/&gt;&lt;DESCR2000&gt;Not available. (30000,8)&lt;/DESCR2000&gt;&lt;t_reserve_array class=&quot;R&quot;&gt;&lt;T_CPE_TYPE&gt;SDSTB&lt;/T_CPE_TYPE&gt;&lt;T_CPE_MODEL/&gt;&lt;T_CPE_TYPE_QTY&gt;0&lt;/T_CPE_TYPE_QTY&gt;&lt;/t_reserve_array&gt;&lt;t_reserve_array class=&quot;R&quot;&gt;&lt;T_CPE_TYPE&gt;SDSTB&lt;/T_CPE_TYPE&gt;&lt;T_CPE_MODEL/&gt;&lt;T_CPE_TYPE_QTY&gt;0&lt;/T_CPE_TYPE_QTY&gt;&lt;/t_reserve_array&gt;&lt;/t_reserve_res&gt;&lt;/reserveCPE_Res_Part&gt;&lt;/reserveCPE_Res&gt;, &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;reserveCPE_Res xmlns=&quot;http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1&quot; xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;&lt;reserveCPE_Res_Part&gt;&lt;t_reserve_res xmlns=&quot;http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1&quot; class=&quot;R&quot;&gt;&lt;T_SUCCESS_FLAG&gt;N&lt;/T_SUCCESS_FLAG&gt;&lt;ORDER_NO/&gt;&lt;DESCR2000&gt;The Business Unit MARIO is not exist. (30000,4)&lt;/DESCR2000&gt;&lt;/t_reserve_res&gt;&lt;/reserveCPE_Res_Part&gt;&lt;/reserveCPE_Res&gt;, &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;reserveCPE_Res xmlns=&quot;http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1&quot; xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;&lt;reserveCPE_Res_Part&gt;&lt;t_reserve_res xmlns=&quot;http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1&quot; class=&quot;R&quot;&gt;&lt;T_SUCCESS_FLAG&gt;N&lt;/T_SUCCESS_FLAG&gt;&lt;ORDER_NO/&gt;&lt;DESCR2000&gt;The Business Unit ERNES is not exist. (30000,4)&lt;/DESCR2000&gt;&lt;/t_reserve_res&gt;&lt;/reserveCPE_Res_Part&gt;&lt;/reserveCPE_Res&gt;]']" mimeType="text/plain" doc:name="Set Payload"/>
        <expression-component doc:name="remove quotes"><![CDATA[payload=payload.replace('[','');]]></expression-component>
        <expression-component doc:name="remote quotes 2"><![CDATA[payload=payload.replace(']','');]]></expression-component>
        <expression-component doc:name="Expression"><![CDATA[payload=payload.replace(',','');]]></expression-component>
    <logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>
</mule>

and produces the following output but as stated the output xml is still an invalid xml and you might want to revisit how your payload is actually getting formed at source and you might want to correct it.

<?xml version="1.0" encoding="UTF-8"?>
<reserveCPE_Res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <reserveCPE_Res_Part>
        <t_reserve_res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1" class="R">
            <T_SUCCESS_FLAG>N</T_SUCCESS_FLAG>
            <ORDER_NO/>
            <DESCR2000>Not available. (300008)</DESCR2000>
            <t_reserve_array class="R">
                <T_CPE_TYPE>SDSTB</T_CPE_TYPE>
                <T_CPE_MODEL/>
                <T_CPE_TYPE_QTY>0</T_CPE_TYPE_QTY>
            </t_reserve_array>
            <t_reserve_array class="R">
                <T_CPE_TYPE>SDSTB</T_CPE_TYPE>
                <T_CPE_MODEL/>
                <T_CPE_TYPE_QTY>0</T_CPE_TYPE_QTY>
            </t_reserve_array>
        </t_reserve_res>
    </reserveCPE_Res_Part>
</reserveCPE_Res>
<?xml version="1.0" encoding="UTF-8"?>
<reserveCPE_Res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <reserveCPE_Res_Part>
        <t_reserve_res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1" class="R">
            <T_SUCCESS_FLAG>N</T_SUCCESS_FLAG>
            <ORDER_NO/>
            <DESCR2000>The Business Unit MARIO is not exist. (300004)</DESCR2000>
        </t_reserve_res>
    </reserveCPE_Res_Part>
</reserveCPE_Res>
<?xml version="1.0" encoding="UTF-8"?>
<reserveCPE_Res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res.VERSION_1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <reserveCPE_Res_Part>
        <t_reserve_res xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas/reserveCPE_Res_Part.VERSION_1" class="R">
            <T_SUCCESS_FLAG>N</T_SUCCESS_FLAG>
            <ORDER_NO/>
            <DESCR2000>The Business Unit ERNES is not exist. (300004)</DESCR2000>
        </t_reserve_res>
    </reserveCPE_Res_Part>
</reserveCPE_Res>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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