Hi,

Your approach with replaceAll seems valid. It's not uncommon to do it like
that. What is your issue with it? Is it slow or do you don't like the
boilerplate code?

As I can see there are various options:

1) Use processor

Move the processor outside the route into a separate Java class
"UnescapeXML".

Then call it like this:

Processor UnescapeXML = new UnescapeXML ();

And in your route:

.process( UnescapeXML)

2) Use transform

For replacements you can also use transform:

.transform(simple( "${body.replace('&amp;lt;', '<')}"))

3) Use xslt (Saxon)

You may also use xslt-saxon:

https://camel.apache.org/components/next/xslt-saxon-component.html

Then call the following xslt (for example unescape.xsl)

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="3.0">

    <xsl:mode on-no-match="shallow-copy"/>

    <xsl:template match="ciRequestXML">
        <xsl:copy>
            <xsl:copy-of select="parse-xml-fragment(.)"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>


Good luck,

Raymond






Op vr 3 dec. 2021 om 07:09 schreef Ajmera, Hemang C
<hemang.ajm...@cgi.com.invalid>:

> Hi
>    You can use xpath to extract ciRequestXML. That should automatically
> have proper xml which can be parsed again.
>
>
> Thanks and Regards,
> Hemang Ajmera
>
>
> -----Original Message-----
> From: Wilken Marci J <marci.j.wil...@dhsoha.state.or.us.INVALID>
> Sent: 03 December 2021 00:55
> To: users@camel.apache.org
> Subject: Converting ;&lt ;&gt to <> in camel
>
>
> EXTERNAL SENDER:   Do not click any links or open any attachments unless
> you trust the sender and know the content is safe.
> EXPÉDITEUR EXTERNE:    Ne cliquez sur aucun lien et n’ouvrez aucune pièce
> jointe à moins qu’ils ne proviennent d’un expéditeur fiable, ou que vous
> ayez l'assurance que le contenu provient d'une source sûre.
>
> Is there a transform or type converter that will convert escaped xml to
> standard xml I get this from a legacy axis 1.4 system
>     <inv:invokeCI>
>          <!--Optional:-->
>          <opCode>R</opCode>
>          <!--Optional:-->
>          <serviceFunction>SelectClientPerpetratorInfo</serviceFunction>
>          <!--Optional:-->
>          <ciRequestXML>
>                     &lt;ParameterBeans&gt;
>                &lt;ParameterBean&gt;
>                   &lt;parameterName&gt;personNo&lt;/parameterName&gt;
>                   &lt;dataType&gt;String&lt;/dataType&gt;
>                   &lt;scale&gt;0&lt;/scale&gt;
>                   &lt;value&gt;WL8AA7Q&lt;/value&gt;
>                &lt;/ParameterBean&gt;
>             &lt;/ParameterBeans&gt;
>          </ciRequestXML>
>          <!--Optional:-->
>          <idWRKRPersn>13887</idWRKRPersn>
>       </inv:invokeCI>
>
>
> I need to convert the ciRequestXML from
>          &lt;ParameterBeans&gt;
>                &lt;ParameterBean&gt;
>                   &lt;parameterName&gt;personNo&lt;/parameterName&gt;
>                   &lt;dataType&gt;String&lt;/dataType&gt;
>                   &lt;scale&gt;0&lt;/scale&gt;
>                   &lt;value&gt;WL8AA7Q&lt;/value&gt;
>                &lt;/ParameterBean&gt;
>             &lt;/ParameterBeans&gt;
> to
>          <ParameterBeans>
>                <ParameterBean>
>                  <parameterName>personNo</parameterName>
>                   <dataType>String</dataType>
>                   <scale>0</scale>
>                   <value>WL8AA7Q</value>
>                </ParameterBean>
>             </ParameterBeans>
> So that I can parse the xml  (am using Jackson)  into a  POJO
>
> Without doing this
> .process(new Processor() {
>                 @SuppressWarnings("unchecked")
>                 public void process(Exchange exchange) throws Exception {
>                         //log.info
> (exchange.getIn().getHeader("RequestBeginDate").getClass().getName());
>                         List<Object> params = (List<Object>)
> exchange.getIn().getBody();
>                         String inboundRequest =
> ((String)params.get(2)).trim()
>
> .replaceAll("&amp;lt;","<")   // fix anything that has been escaped
>
> .replaceAll("&amp;gt;",">")
>
> .replaceAll("&lt;","<")   // fix anything that has been escaped
>
> .replaceAll("&gt;",">")
>                                                                         ;
>                         log.info("Inbound Request: " + inboundRequest);
>                         exchange.getMessage().setBody(inboundRequest);
>
>
>
>                 }})
>
>
>
> Regards-
> Marci Wilken
> She/Her/Hers
> Operations Architect
> Office of Information Services
> OHA/DHS/CAF-CW/OR-KIDS
> Desk: 503.378.2405 Cell: 503.979.9680
>
> CONFIDENTIALITY NOTICE
> This email may contain information that is privileged, confidential, or
> otherwise exempt from disclosure under applicable law. If you are not the
> addressee or it appears from the context or otherwise that you have
> received this email in error, please advise me immediately by reply email,
> keep the contents confidential, and immediately delete the message and any
> attachments from your system.
>
>
>

Reply via email to