Replacing value in an XML file using replaceregexp

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Replacing value in an XML file using replaceregexp

omkar
I want to replace three values from files(12467abc,12467def,12467xyz).

<sample>IF(  TEXT( $User.ABC_USR_Brand__c )=&quot;Maruti&quot;,
&quot;/servlet/servlet.FileDownload?file=12467abc&quot;,
 IF ( TEXT($User.ABC_USR_Brand__c )=&quot;Maruti Suzuki&quot;,
&quot;/servlet/servlet.FileDownload?file=12467def&quot;,
&quot;/servlet/servlet.FileDownload?file=12467xyz&quot;))</sample>

I want to replace below values in above lines using build.xml file.

Replace:

    12467abc => 34567abc
    12467def => 34567def
12467xyz => 34567xyz

I have made this query please suggest. I will use below query two times as
there is two numbers to replace. <replaceregexp byline="false" match="
(?=&lt;group&gt;12467abc)(.*)(?=&lt;\/group&gt;)" replace="
&lt;group&gt;34567abc" flags="g"> <fileset dir="../src/store/"><include
name="*.xml"/></fileset> </replaceregexp>
Reply | Threaded
Open this post in threaded view
|

AW: Replacing value in an XML file using replaceregexp

Jan Matèrne (jhm)
Simple solution
        <copy tofile="test.txt" file="file.txt"/>
        <replaceregexp file="test.txt" match="12467abc" replace="34567abc" byline="true"/>
        <replaceregexp file="test.txt" match="12467def" replace="34567def" byline="true"/>
        <replaceregexp file="test.txt" match="12467xyz" replace="34567xyz" byline="true"/>
        <concat><fileset file="test.txt"/></concat>

Another possibility is using a template file and <copy><filterchain><replacetokens>.

The simple solution is based on your "requirement"
  > Replace:
  > 12467abc => 34567abc
  > 12467def => 34567def
  > 12467xyz => 34567xyz

For heavy xml modifications you could use the external xml tasks
http://ant.apache.org/external.html#XmlTask


Jan


> -----Ursprüngliche Nachricht-----
> Von: Om Omkar [mailto:[hidden email]]
> Gesendet: Mittwoch, 16. Oktober 2019 11:55
> An: [hidden email]; [hidden email]; [hidden email]
> Betreff: Replacing value in an XML file using replaceregexp
>
> I want to replace three values from files(12467abc,12467def,12467xyz).
>
> <sample>IF(  TEXT( $User.ABC_USR_Brand__c )=&quot;Maruti&quot;,
> &quot;/servlet/servlet.FileDownload?file=12467abc&quot;,
>  IF ( TEXT($User.ABC_USR_Brand__c )=&quot;Maruti Suzuki&quot;,
> &quot;/servlet/servlet.FileDownload?file=12467def&quot;,
> &quot;/servlet/servlet.FileDownload?file=12467xyz&quot;))</sample>
>
> I want to replace below values in above lines using build.xml file.
>
> Replace:
>
>     12467abc => 34567abc
>     12467def => 34567def
> 12467xyz => 34567xyz
>
> I have made this query please suggest. I will use below query two times
> as there is two numbers to replace. <replaceregexp byline="false"
> match="
> (?=&lt;group&gt;12467abc)(.*)(?=&lt;\/group&gt;)" replace="
> &lt;group&gt;34567abc" flags="g"> <fileset dir="../src/store/"><include
> name="*.xml"/></fileset> </replaceregexp>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]