Remove external tag with xpath wso2

不打扰是莪最后的温柔 提交于 2020-12-15 05:28:40

问题


how can I achieve this with xpath in wso2?

Example:

    <TEMP>
            <NAME>GEORGE</NAME>
            <COGNOME>MENDEZ</COGNOME>
            <BUSINESSNAME/>
            <CHANNEL>X091</CHANNEL>
        
   </TEMP>

Result:

<NAME>GEORGE</NAME>
<COGNOME>MENDEZ</COGNOME>
<BUSINESSNAME/>
<CHANNEL>X091</CHANNEL>
    

Thanks


回答1:


The XML generated needs to have a root element. Therefore you will not be able to create the following payload, which does not have a root element.

<NAME>GEORGE</NAME>
<COGNOME>MENDEZ</COGNOME>
<BUSINESSNAME/>
<CHANNEL>X091</CHANNEL>

Update

As per the comments given what I understand is that, you have the following payload saved in a property.

<ELEMENT>
     <ELEMENT_2>
        <ELEMENT_3>
           <ID>173993</ID>
        </ELEMENT_3>
     </ELEMENT_2>
</ELEMENT>

There is another payload as follows. (I have used an endpoint call to get the following payload)

<TEMP>
    <NAME>GEORGE</NAME>
    <COGNOME>MENDEZ</COGNOME>
    <BUSINESSNAME/>
    <CHANNEL>X091</CHANNEL>
</TEMP>

Based on this payload you need to enrich the initial property to have the following payload.

<ELEMENT>
   <ELEMENT_2>
      <ELEMENT_3>
         <ID>173993</ID>
      </ELEMENT_3>
      <NAME>GEORGE</NAME>
      <COGNOME>MENDEZ</COGNOME>
      <BUSINESSNAME />
      <CHANNEL>X091</CHANNEL>
   </ELEMENT_2>
</ELEMENT>

You can check the following sample proxy and check whether you can achieve your requirement.

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="enrichProxy"
       startOnLoad="true"
       statistics="disable"
       trace="disable"
       transports="http,https">
   <target>
      <inSequence>
         <property name="initial_payload" scope="default">
            <ELEMENT xmlns="">
               <ELEMENT_2>
                  <ELEMENT_3>
                     <ID>173993</ID>
                  </ELEMENT_3>
               </ELEMENT_2>
            </ELEMENT>
         </property>
         <call>
            <endpoint>
               <http uri-template="http://run.mocky.io/v3/7c578a1d-5427-4325-9f00-4ad7bb80dd04"/>
            </endpoint>
         </call>
         <log level="custom">
            <property expression="$body//TEMP/*" name="******"/>
         </log>
         <respond/>
      </inSequence>
   </target>
   <description/>
</proxy>
          

                  


来源:https://stackoverflow.com/questions/64841917/remove-external-tag-with-xpath-wso2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!