如何从 mule ESB 中的有效负载中删除括号?



目前我有一个带有括号的有效负载和一个用于分隔每一行的,。这个想法是删除开头的[和结尾的],以及中间的,

有什么想法吗?

[<?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>]

我的评论太长了,无法在评论部分发布,因此请在此处发布。

这就是您的有效负载的外观。

[<?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>]

在每个逗号之后都有一个新的 XML 开始,因此您不能在一个 XML 下嵌入多个 XML,除非您尝试在 XML 中拥有多行数据。

您要做的第一件事是将您的输入转换为格式正确的 XML,目前它不是。 看看您的有效负载中的所有这些, <?xml version="1.0" encoding="UTF-8"?>使其成为垃圾。

以下代码将执行您要查找的操作

<?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:UserssatichenDesktopworktest" workDirectory="C:UserssatichenDesktopsaruku" 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>

并生成以下输出,但如前所述,输出 XML 仍然是无效的 XML,您可能希望重新审视有效负载在源中的实际形成方式,并且可能需要更正它。

<?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>

最新更新