Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a fragment of my own solution. I won't mark it as accepted, because it doesn't solve the general text-parse problem (like php's preg_match_all). But maybe someone find it interesting. It is a little bit messy - I use ant properties and flaka EL variables, but it illustrates how to use them together. Here's the code:</p> <pre><code>filename: process.xml </code></pre> <p> </p> <pre><code>&lt;!-- these includes are needed so that eclipse can load autocompletion base from plugins, and they tell to ant where plugins' jars are (in 'ut' folder on the same level)--&gt; &lt;taskdef uri="antlib:it.haefelinger.flaka" resource="it/haefelinger/flaka/antlib.xml" classpath="ut/ant-flaka.jar" /&gt; &lt;taskdef uri="antlib:net.sf.antcontrib" resource="net/sf/antcontrib/antlib.xml" classpath="ut/ant-contrib-1.0b3.jar" /&gt; &lt;!-- call: &gt;&gt; ant -Dfname="folder/with/xmls" -f process.xml correct-xmls --&gt; &lt;target name="correct-xmls"&gt; &lt;fl:install-property-handler /&gt; &lt;property name="slashn" value="${line.separator}" /&gt; &lt;!-- get xmls - only with existing root resprops element --&gt; &lt;fileset dir="${fname}" includes="**/*.xml" id="xml-classes"&gt; &lt;contains text="&amp;lt;resprops&amp;gt;" /&gt; &lt;/fileset&gt; &lt;fl:for var="xn" in="split('${toString:xml-classes}', ';')"&gt; &lt;fl:let&gt;curfile = file(concat('${fname}','/',xn))&lt;/fl:let&gt; &lt;fl:let&gt;tgtfile = file(concat('${fname}','/',xn,'.new'))&lt;/fl:let&gt; &lt;fl:echo&gt;#{ format('file %s, last modified %tD, size: %d', curfile.path, curfile.mtime, curfile.isdir ? 0 : curfile.size) }&lt;/fl:echo&gt; &lt;fl:unset&gt;xmlfile.contents&lt;/fl:unset&gt; &lt;loadfile property="xmlfile.contents" srcFile="#{curfile}" /&gt; &lt;fl:let&gt;outstr = ''&lt;/fl:let&gt; &lt;fl:for var="str" in="split('${xmlfile.contents}', '\n')"&gt; &lt;fl:unset&gt; xval &lt;/fl:unset&gt; &lt;ac:propertyregex property="xval" input="#{str}" regexp="pos-x\s*=\s*&amp;quot;([0-9\-]+)&amp;quot;" select="\1" override="true" /&gt; &lt;!-- force set property 'resstr' to value of var 'str'--&gt; &lt;fl:let&gt;resstr ::= str&lt;/fl:let&gt; &lt;!-- process only if pos-x is found and we have its value in 'xval' --&gt; &lt;fl:when test="not empty '#{property.xval}'"&gt; &lt;fl:let&gt;outval = (property.xval * 15.5 + 0.5) &lt;/fl:let&gt; &lt;!-- kinda int-from-float --&gt; &lt;ac:propertyregex property="gotv" input="#{outval}" regexp="([0-9\-]+)\." select="\1" override="true" /&gt; &lt;ac:propertyregex property="resstr" input="${resstr}" regexp="pos-x\s*=\s*&amp;quot;([0-9\-]+)&amp;quot;" replace="pos-x = &amp;quot;#{gotv}&amp;quot;" override="true" /&gt; &lt;/fl:when&gt; &lt;!-- add to output string by string --&gt; &lt;fl:let&gt; outstr = format('%s%s%s', outstr , resstr, slashn) &lt;/fl:let&gt; &lt;/fl:for&gt; &lt;!--save processed file --&gt; &lt;echo file="#{tgtfile}" encoding="utf-8"&gt;#{outstr}&lt;/echo&gt; &lt;/fl:for&gt; &lt;/target&gt; </code></pre> <p></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload