You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Jowie <jo...@mac.com> on 2009/12/07 13:02:05 UTC

RegExp help needed!

Hi all,

I'm fumbling my way around Ant and finding the help on the web really
confusing. I am using Ant simply as a macro copy/download/find-replace
utility and am an ActionScript programmer, not a Java one.

Anyway... There's one bit I'm stuck on and really need your help please!

I have used Ant to download an XML file and store it locally. I now need a
way of going through the XML, finding all the image URL attributes,
downloading those images and replacing all the URLs in the XML to local
relative paths. So far, all I have is:

		<loadfile property="questions" srcFile="${local.path}GetAllQuestions.xml"
/>
		<propertyregex input="${questions}" property="questions.output"
regexp="Media=&quot;(.*?)&quot;" select="\1" global="true" />
		<echo message="${questions.output}" />

This only traces the first one in the XML, but obviously I want to find all
of the instances, add them to some kind of array and then loop through that
array and load them all. I've done a for list before so that bit is okay,
but the question is how do I get Ant to iterate through and find all
individual instances of that regexp?

Please help... Thanks!

:-Joe
-- 
View this message in context: http://old.nabble.com/RegExp-help-needed%21-tp26676257p26676257.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: RegExp help needed!

Posted by Jowie <jo...@mac.com>.
Okay,

So I've sorted it, but it was a weird one!

One of the questions was badly formatted, and looked like this:

  <Question ID="531" Subject="L" Category="Punc" Presentation="PT01"
Engine="MC01" Body="test" Instruction="Select the correct answer" Level="1">
    <TipID/>
    <Answers>
      <Answer ID="1457" Valid="false" Position="1"
Media="/bgmain/Image.ashx?ID=112">[Media}</Answer>
      <Answer ID="1458" Valid="true" Position="2"
Media="/bgmain/Image.ashx?ID=113">[Media}</Answer>
      <Answer ID="1459" Valid="false" Position="3"
Media="/bgmain/Image.ashx?ID=114">[Media}</Answer>
      <Answer ID="1460" Valid="false" Position="4"
Media="/bgmain/Image.ashx?ID=115">[Media}</Answer>
    </Answers>
  </Question>

Notice the "[Media}"... Now the weird thing is that this caused an error on
a large file, but not on a smaller one. I can correct the problem from my
end, but I thought you might like to know! Is a "}" symbol not allowed in
UTF-encoded XML files? It seems to work fine in a browser and like I said,
also works fine in smaller files...

weird!
-- 
View this message in context: http://old.nabble.com/RegExp-help-needed%21-tp26676257p26677635.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: RegExp help needed!

Posted by Jowie <jo...@mac.com>.
Hi there,

Just so you know, I created a file which was bigger than my original file as
a test, and that worked fine... So I'm a bit confused as to how this XML
file will not work when it is supposedly well formatted...

??
-- 
View this message in context: http://old.nabble.com/RegExp-help-needed%21-tp26676257p26677454.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: RegExp help needed!

Posted by Antoine Levy Lambert <an...@gmx.de>.
Hi,

uhhm, in this case maybe the error you are encountering is a disguised 
Out of Memory, or a bug with the XML parser.

you might want to try with different JDKs. I do not know whether the 
xercesImpl.jar which ships with ant is actually used to parse XML files 
in custom tasks or whether it would be some equivalent package from your 
JDK. I wonder whether ant would run without the xercesImpl.jar. I guess 
it is not needed with the recent JDKs.

Regards,

Antoine

Jowie wrote:
> Hi Antopine,
>
> Yes the XML file loads fine in a browser. I am even declaring UTF-8 at the
> top of the file. And when I split the file down the middle and test both
> halves (keeping the header of course) it works fine too.
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: RegExp help needed!

Posted by Jowie <jo...@mac.com>.
Hi Antopine,

Yes the XML file loads fine in a browser. I am even declaring UTF-8 at the
top of the file. And when I split the file down the middle and test both
halves (keeping the header of course) it works fine too.



Hello,

the error below would not be an ant of xmltask error. The message

Invalid byte 3 of 3-byte UTF-8 sequence

 means that your XML file is not matching the UTF-8 convention. Does 
your XML file specify UTF-8 in the XML declaration ?

Can you read your XML file using another tool than ant, for instance a 
web browser, or the XML editor of Eclipse or another Java based 
development environment ?

Regards,

Antopine
-- 
View this message in context: http://old.nabble.com/RegExp-help-needed%21-tp26676257p26677322.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: RegExp help needed!

Posted by Antoine Levy Lambert <an...@gmx.de>.
Hello,

the error below would not be an ant of xmltask error. The message

Invalid byte 3 of 3-byte UTF-8 sequence

 means that your XML file is not matching the UTF-8 convention. Does 
your XML file specify UTF-8 in the XML declaration ?

Can you read your XML file using another tool than ant, for instance a 
web browser, or the XML editor of Eclipse or another Java based 
development environment ?

Regards,

Antopine

Jowie wrote:
> Doh... Looks like I have a problem using xmltask anyway unfortunately... The
> GetAllQuestions.xml is too big for it to handle :-( it's nearly 1MB in size.
> At least I'm pretty sure that's why, since if I run another piece of XML
> which is a lot smaller it works fine. But in this case I get the error:
>
>
>   [xmltask]
> com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException:
> Invalid byte 3 of 3-byte UTF-8 sequence.
>   [xmltask] 	at
> com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(Unknown
> Source)
>   [xmltask] 	at
> com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(Unknown Source)
>   [xmltask] 	at
> com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(Unknown
> Source)
>   [xmltask] 	at
> com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipChar(Unknown
> Source)
>   [xmltask] 	at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown
> Source)
>   [xmltask] 	at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown
> Source)
>   [xmltask] 	at
> com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown
> Source)
>   [xmltask] 	at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
> Source)
>   [xmltask] 	at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
> Source)
>   [xmltask] 	at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
> Source)
>   [xmltask] 	at
> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
>   [xmltask] 	at
> com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
>   [xmltask] 	at
> com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown
> Source)
>   [xmltask] 	at
> com.oopsconsultancy.xmltask.ant.XmlTask.documentFromStream(XmlTask.java:343)
>   [xmltask] 	at
> com.oopsconsultancy.xmltask.ant.XmlTask.documentFromFile(XmlTask.java:387)
>   [xmltask] 	at
> com.oopsconsultancy.xmltask.ant.XmlTask.access$000(XmlTask.java:27)
>   [xmltask] 	at
> com.oopsconsultancy.xmltask.ant.XmlTask$InputFile.getDocument(XmlTask.java:203)
>   [xmltask] 	at
> com.oopsconsultancy.xmltask.ant.XmlTask.execute(XmlTask.java:638)
>   [xmltask] 	at
> org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
>   [xmltask] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>   [xmltask] 	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>   [xmltask] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
> Source)
>   [xmltask] 	at java.lang.reflect.Method.invoke(Unknown Source)
>   [xmltask] 	at
> org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
>   [xmltask] 	at org.apache.tools.ant.Task.perform(Task.java:348)
>   [xmltask] 	at org.apache.tools.ant.Target.execute(Target.java:357)
>   [xmltask] 	at org.apache.tools.ant.Target.performTasks(Target.java:385)
>   [xmltask] 	at
> org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
>   [xmltask] 	at
> org.apache.tools.ant.Project.executeTarget(Project.java:1306)
>   [xmltask] 	at
> org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
>   [xmltask] 	at
> org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
>   [xmltask] 	at
> org.apache.tools.ant.Project.executeTargets(Project.java:1189)
>   [xmltask] 	at
> org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
>   [xmltask] 	at
> org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
>
> BUILD FAILED
> C:\Work\LSIS\Brain Games\Main\ant\update_offline.xml:77: Invalid byte 3 of
> 3-byte UTF-8 sequence.
>
>
> ----
>
>
> Bad times :(
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: RegExp help needed!

Posted by Joe Nash <jo...@mac.com>.
> That looks to me like your XML is not properly encoded. I 
> suspect that if you use a command-line tool like xmlstarlet 
> it'll confoirm that by giving you a very similar error. The 
> below isn't size-related.

Thanks for the info. If you are right, this could still be a problem because
the XML is being formed on a server and I don't really have control over
that part of it!

I just tried splitting the file into two to test that theory... Both halves
seem to work fine, but together they throw that error.

I also ran the XML file in Firefox to see what it thinks of the file, and it
doesn't throw any encoding errors.

:(


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: RegExp help needed!

Posted by Jowie <jo...@mac.com>.

> That looks to me like your XML is not properly encoded. I 
> suspect that if you use a command-line tool like xmlstarlet 
> it'll confoirm that by giving you a very similar error. The 
> below isn't size-related.

Thanks for the info. If you are right, this could still be a problem because
the XML is being formed on a server and I don't really have control over
that part of it!

I just tried splitting the file into two to test that theory... Both halves
seem to work fine, but together they throw that error.

I also ran the XML file in Firefox to see what it thinks of the file, and it
doesn't throw any encoding errors.

:(
-- 
View this message in context: http://old.nabble.com/RegExp-help-needed%21-tp26676257p26677279.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: RegExp help needed!

Posted by Brian Agnew <br...@oopsconsultancy.com>.
That looks to me like your XML is not properly encoded. I suspect that 
if you use a command-line tool like xmlstarlet it'll confoirm that by 
giving you a very similar error. The below isn't size-related.

On 07/12/2009 13:15, Jowie wrote:
> Doh... Looks like I have a problem using xmltask anyway unfortunately... The
> GetAllQuestions.xml is too big for it to handle :-( it's nearly 1MB in size.
> At least I'm pretty sure that's why, since if I run another piece of XML
> which is a lot smaller it works fine. But in this case I get the error:
>
>
>    [xmltask]
> com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException:
> Invalid byte 3 of 3-byte UTF-8 sequence.
>    [xmltask] 	at
> com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(Unknown
> Source)
>    [xmltask] 	at
> com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(Unknown Source)
>    [xmltask] 	at
> com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(Unknown
> Source)
>    [xmltask] 	at
> com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipChar(Unknown
> Source)
>    [xmltask] 	at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown
> Source)
>    [xmltask] 	at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown
> Source)
>    [xmltask] 	at
> com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown
> Source)
>    [xmltask] 	at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
> Source)
>    [xmltask] 	at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
> Source)
>    [xmltask] 	at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
> Source)
>    [xmltask] 	at
> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
>    [xmltask] 	at
> com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
>    [xmltask] 	at
> com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown
> Source)
>    [xmltask] 	at
> com.oopsconsultancy.xmltask.ant.XmlTask.documentFromStream(XmlTask.java:343)
>    [xmltask] 	at
> com.oopsconsultancy.xmltask.ant.XmlTask.documentFromFile(XmlTask.java:387)
>    [xmltask] 	at
> com.oopsconsultancy.xmltask.ant.XmlTask.access$000(XmlTask.java:27)
>    [xmltask] 	at
> com.oopsconsultancy.xmltask.ant.XmlTask$InputFile.getDocument(XmlTask.java:203)
>    [xmltask] 	at
> com.oopsconsultancy.xmltask.ant.XmlTask.execute(XmlTask.java:638)
>    [xmltask] 	at
> org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
>    [xmltask] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>    [xmltask] 	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>    [xmltask] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
> Source)
>    [xmltask] 	at java.lang.reflect.Method.invoke(Unknown Source)
>    [xmltask] 	at
> org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
>    [xmltask] 	at org.apache.tools.ant.Task.perform(Task.java:348)
>    [xmltask] 	at org.apache.tools.ant.Target.execute(Target.java:357)
>    [xmltask] 	at org.apache.tools.ant.Target.performTasks(Target.java:385)
>    [xmltask] 	at
> org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
>    [xmltask] 	at
> org.apache.tools.ant.Project.executeTarget(Project.java:1306)
>    [xmltask] 	at
> org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
>    [xmltask] 	at
> org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
>    [xmltask] 	at
> org.apache.tools.ant.Project.executeTargets(Project.java:1189)
>    [xmltask] 	at
> org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
>    [xmltask] 	at
> org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
>
> BUILD FAILED
> C:\Work\LSIS\Brain Games\Main\ant\update_offline.xml:77: Invalid byte 3 of
> 3-byte UTF-8 sequence.
>
>
> ----
>
>
> Bad times :(
>    

-- 
Brian Agnew                  http://www.oopsconsultancy.com
OOPS Consultancy Ltd
Tel: +44 (0)7720 397526
Fax: +44 (0)20 8682 0012


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: RegExp help needed!

Posted by Jowie <jo...@mac.com>.
Doh... Looks like I have a problem using xmltask anyway unfortunately... The
GetAllQuestions.xml is too big for it to handle :-( it's nearly 1MB in size.
At least I'm pretty sure that's why, since if I run another piece of XML
which is a lot smaller it works fine. But in this case I get the error:


  [xmltask]
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException:
Invalid byte 3 of 3-byte UTF-8 sequence.
  [xmltask] 	at
com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(Unknown
Source)
  [xmltask] 	at
com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(Unknown Source)
  [xmltask] 	at
com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(Unknown
Source)
  [xmltask] 	at
com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipChar(Unknown
Source)
  [xmltask] 	at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown
Source)
  [xmltask] 	at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown
Source)
  [xmltask] 	at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown
Source)
  [xmltask] 	at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
  [xmltask] 	at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source)
  [xmltask] 	at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source)
  [xmltask] 	at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
  [xmltask] 	at
com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
  [xmltask] 	at
com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown
Source)
  [xmltask] 	at
com.oopsconsultancy.xmltask.ant.XmlTask.documentFromStream(XmlTask.java:343)
  [xmltask] 	at
com.oopsconsultancy.xmltask.ant.XmlTask.documentFromFile(XmlTask.java:387)
  [xmltask] 	at
com.oopsconsultancy.xmltask.ant.XmlTask.access$000(XmlTask.java:27)
  [xmltask] 	at
com.oopsconsultancy.xmltask.ant.XmlTask$InputFile.getDocument(XmlTask.java:203)
  [xmltask] 	at
com.oopsconsultancy.xmltask.ant.XmlTask.execute(XmlTask.java:638)
  [xmltask] 	at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
  [xmltask] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  [xmltask] 	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  [xmltask] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
Source)
  [xmltask] 	at java.lang.reflect.Method.invoke(Unknown Source)
  [xmltask] 	at
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
  [xmltask] 	at org.apache.tools.ant.Task.perform(Task.java:348)
  [xmltask] 	at org.apache.tools.ant.Target.execute(Target.java:357)
  [xmltask] 	at org.apache.tools.ant.Target.performTasks(Target.java:385)
  [xmltask] 	at
org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
  [xmltask] 	at
org.apache.tools.ant.Project.executeTarget(Project.java:1306)
  [xmltask] 	at
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
  [xmltask] 	at
org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
  [xmltask] 	at
org.apache.tools.ant.Project.executeTargets(Project.java:1189)
  [xmltask] 	at
org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
  [xmltask] 	at
org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)

BUILD FAILED
C:\Work\LSIS\Brain Games\Main\ant\update_offline.xml:77: Invalid byte 3 of
3-byte UTF-8 sequence.


----


Bad times :(
-- 
View this message in context: http://old.nabble.com/RegExp-help-needed%21-tp26676257p26677094.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: RegExp help needed!

Posted by Jowie <jo...@mac.com>.
Okay... So back to my original request (thanks for all the help so far! :))

Here's my code so far:

------------
	<target name="downloadQuestionImages">
		<xmltask source="${local.path}GetAllQuestions.xml">
			<call path="//@Media" target="getMedia">
				
			</call>
		</xmltask>
	</target>
	
	<target name="getMedia">
		<echo message="${mediaURL}" />
	</target>
-------------

This doesn't seem to iterate through though... I get:

getMedia:
     [echo] /brain_games_main/Image.ashx?ID=647
  [xmltask] Parent project doesn't contain any reference 'xmltask.buffers'

And just keeps looping.

Any thoughts? Thanks!

:-Joe
-- 
View this message in context: http://old.nabble.com/RegExp-help-needed%21-tp26676257p26677773.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: RegExp help needed!

Posted by Jowie <jo...@mac.com>.
I think the problem that I have is that the @Media property isn't always set.
In which case it fails when it tries to look at a node with no Media
property.

Can anyone think of a workaround? :-/

Thanks!
-- 
View this message in context: http://old.nabble.com/RegExp-help-needed%21-tp26676257p26679175.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: RegExp help needed!

Posted by Jowie <jo...@mac.com>.
Hopefully it will work this time... This is my code:

<![CDATA[

<target name="downloadQuestionImages">
    <xmltask source="${local.path}GetAllQuestions.xml">
        <call path="//@Media" buffer="media">
            
            <actions>
                <echo>img = @{img}</echo>
            </actions>
        </call>
    </xmltask>
</target>

]]>

and I get back:

     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647

etc.... 

Sorry everyone for the repeat postings! I'm really starting to scratch my
head sore on this one! :-/
-- 
View this message in context: http://old.nabble.com/RegExp-help-needed%21-tp26676257p26679059.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: RegExp help needed!

Posted by Jowie <jo...@mac.com>.
Hi Gilbert,

Sorry my copied code was completely wrong! Have no idea why! It should have
been:

		<xmltask source="${local.path}GetAllQuestions.xml">
			<call path="//*">
				
				<actions>
					<echo>img = @{img}</echo>
				</actions>
			</call>
		</xmltask>

And I get back:

     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647

etc... Rather than different attribute each time
-- 
View this message in context: http://old.nabble.com/RegExp-help-needed%21-tp26676257p26678408.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: RegExp help needed!

Posted by Jowie <jo...@mac.com>.
Hi again Gilbert,

That updated Xpath worked a treat... Thank you very much for your patience
and help! :-)

Hopefully that will be it now... ;-)

Cheers again!

:-Joe
-- 
View this message in context: http://old.nabble.com/RegExp-help-needed%21-tp26676257p26679471.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: RegExp help needed!

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.

-----Original Message-----
From: Jowie [mailto:joe.nash@mac.com] 
Sent: Monday, December 07, 2009 4:06 PM
To: user@ant.apache.org
Subject: RE: RegExp help needed!

/*
Hi Gilbert,

What I am trying to say is... I have done exactly how you say, despite what
my last message says (some weird URL encoding is deleting one of my lines!)
and it returns a list of repeating

     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647

rather than different IDs each time...

Sorry for the confusion!
*/

i'm sorry too, the xpath expression was wrong, so here we go

your input =

<Question ID="531" Subject="L" Category="Punc" Presentation="PT01"
  Engine="MC01" Body="test" Media="/bgmain/Image.ashx?ID=12">
  <TipID />
  <Answers>
    <Answer ID="1457" Valid="false" Position="1"
      Media="/bgmain/Image.ashx?ID=112">txt
    </Answer>
    <Answer ID="1458" Valid="true" Position="2"
      Media="/bgmain/Image.ashx?ID=113">txt
    </Answer>
    <Answer ID="1459" Valid="false" Position="3"
      Media="/bgmain/Image.ashx?ID=114">txt
    </Answer>
    <Answer ID="1460" Valid="false" Position="4"
      Media="/bgmain/Image.ashx?ID=115">txt
    </Answer>
  </Answers>
</Question>


and =

<xmltask source="xpathtest.xml">
<call path="//*[@Media]">
  <param name="img" path="@Media"/>
  <actions>
      <echo>img = @{img}</echo>
  </actions>
</call>
</xmltask>

gives =

     [echo] img = /bgmain/Image.ashx?ID=12
     [echo] img = /bgmain/Image.ashx?ID=112
     [echo] img = /bgmain/Image.ashx?ID=113
     [echo] img = /bgmain/Image.ashx?ID=114
     [echo] img = /bgmain/Image.ashx?ID=115


if you need only the @Media attributes under from Answer
nodes, use the expresssion  =
<call path="//Answer[@Media]">
...

gives =

     [echo] img = /bgmain/Image.ashx?ID=112
     [echo] img = /bgmain/Image.ashx?ID=113
     [echo] img = /bgmain/Image.ashx?ID=114
     [echo] img = /bgmain/Image.ashx?ID=115




Gilbert


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: RegExp help needed!

Posted by Jowie <jo...@mac.com>.
Hi Gilbert,

What I am trying to say is... I have done exactly how you say, despite what
my last message says (some weird URL encoding is deleting one of my lines!)
and it returns a list of repeating

     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647

rather than different IDs each time...

Sorry for the confusion!
-- 
View this message in context: http://old.nabble.com/RegExp-help-needed%21-tp26676257p26678500.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: RegExp help needed!

Posted by Jowie <jo...@mac.com>.
ARRRRGH!!

I am posting another line here... I have done *exactly* what you say - that
line gap is a weird mistake! But I get back a load of repeating echoes ... 

Cheers



Jowie wrote:
> 
> Hi Gilbert,
> 
> Sorry my copied code was completely wrong! Have no idea why! It should
> have been:
> 
> 		<xmltask source="${local.path}GetAllQuestions.xml">
> 			<call path="//*">
> 				
> 				<actions>
> 					<echo>img = @{img}</echo>
> 				</actions>
> 			</call>
> 		</xmltask>
> 
> And I get back:
> 
>      [echo] img = /brain_games_main/Image.ashx?ID=647
>      [echo] img = /brain_games_main/Image.ashx?ID=647
>      [echo] img = /brain_games_main/Image.ashx?ID=647
>      [echo] img = /brain_games_main/Image.ashx?ID=647
>      [echo] img = /brain_games_main/Image.ashx?ID=647
>      [echo] img = /brain_games_main/Image.ashx?ID=647
>      [echo] img = /brain_games_main/Image.ashx?ID=647
>      [echo] img = /brain_games_main/Image.ashx?ID=647
>      [echo] img = /brain_games_main/Image.ashx?ID=647
>      [echo] img = /brain_games_main/Image.ashx?ID=647
>      [echo] img = /brain_games_main/Image.ashx?ID=647
>      [echo] img = /brain_games_main/Image.ashx?ID=647
>      [echo] img = /brain_games_main/Image.ashx?ID=647
>      [echo] img = /brain_games_main/Image.ashx?ID=647
>      [echo] img = /brain_games_main/Image.ashx?ID=647
>      [echo] img = /brain_games_main/Image.ashx?ID=647
> 
> etc... Rather than different attribute each time
> 

-- 
View this message in context: http://old.nabble.com/RegExp-help-needed%21-tp26676257p26678458.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: RegExp help needed!

Posted by Jowie <jo...@mac.com>.
Hi Gilbert,

Sorry my copied code was completely wrong! Have no idea why! It should have
been:

		<xmltask source="${local.path}GetAllQuestions.xml">
			<call path="//*">
				
				<actions>
					<echo>img = @{img}</echo>
				</actions>
			</call>
		</xmltask>

And I get back:

     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647

etc... Rather than different attribute each time
-- 
View this message in context: http://old.nabble.com/RegExp-help-needed%21-tp26676257p26678362.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: RegExp help needed!

Posted by Jowie <jo...@mac.com>.
Hopefully it will work this time... This is my code:


    
        
            
            
                img = @{img}
            
        
    


]]>

and I get back:

I get back:

     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647

etc.... 

Sorry everyone for the repeat postings! I'm really starting to scratch my
head sore on this one! :-/
-- 
View this message in context: http://old.nabble.com/RegExp-help-needed%21-tp26676257p26679046.html
Sent from the Ant - Users mailing list archive at Nabble.com.

RE: RegExp help needed!

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
 

-----Original Message-----
From: Jowie [mailto:joe.nash@mac.com] 
Sent: Monday, December 07, 2009 3:28 PM
To: user@ant.apache.org
Subject: RE: RegExp help needed!

/*
[...]

 Games\Main\ant\update_offline.xml:77: required attribute
img not set

But... If I do

		<xmltask source="${local.path}GetAllQuestions.xml">
			<call path="//*">
				<!-- target="getMedia" buffer="abc"-->
				
				<actions>
				    <echo>img = @{img}</echo>
				</actions>
			</call>
		</xmltask>

I get back:

     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647

etc....
*/


when using <actions> ... </actions> instead
of <all path="..." target="...">  you have to write =

<xmltask source="xpathtest.xml">
  <call path="//*">
    <param name="img" path="//@Media"/>
     <actions>
       <echo>img = @{img}</echo>
      </actions>
   </call>
</xmltask>

to match all Media attributes.



Gilbert


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: RegExp help needed!

Posted by Jowie <jo...@mac.com>.
Thanks Gilbert...

I have now got this...

		<xmltask source="${local.path}GetAllQuestions.xml">
			<call path="//*">
				
				<actions>
				    <echo>img = @{img}</echo>
				</actions>
			</call>
		</xmltask>

which returns:

BUILD FAILED
C:\Work\LSIS\Brain Games\Main\ant\update_offline.xml:77: required attribute
img not set

But... If I do

		<xmltask source="${local.path}GetAllQuestions.xml">
			<call path="//*">
				<!-- target="getMedia" buffer="abc"-->
				
				<actions>
				    <echo>img = @{img}</echo>
				</actions>
			</call>
		</xmltask>

I get back:

     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647
     [echo] img = /brain_games_main/Image.ashx?ID=647

etc....




Rebhan, Gilbert wrote:
> 
> 
> P.S. :
> 
> <call path="/Question/Answers/*" target="foo">
>   
> </call>
> 
> will hit all Media=... attributes und /Question/Answers,
> if you need all Media Attributes you need to use =
> 
> <call path="//*" target="foo">
>   
> </call>
> 
> 
> Regards, Gilbert
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/RegExp-help-needed%21-tp26676257p26678002.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: RegExp help needed!

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
P.S. :

<call path="/Question/Answers/*" target="foo">
  <param name="img" path="@Media" />
</call>

will hit all Media=... attributes und /Question/Answers,
if you need all Media Attributes you need to use =

<call path="//*" target="foo">
  <param name="img" path="@Media" />
</call>


Regards, Gilbert
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: RegExp help needed!

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
 
-----Original Message-----
From: Jowie [mailto:joe.nash@mac.com] 
Sent: Monday, December 07, 2009 1:40 PM
To: user@ant.apache.org
Subject: RE: RegExp help needed!

/*
  <Question ID="531" Subject="L" Category="Punc" Presentation="PT01"
Engine="MC01" Body="test" Media="/bgmain/Image.ashx?ID=12">
    <TipID/>
    <Answers>
      <Answer ID="1457" Valid="false" Position="1"
Media="/bgmain/Image.ashx?ID=112">txt</Answer>
      <Answer ID="1458" Valid="true" Position="2"
Media="/bgmain/Image.ashx?ID=113">txt</Answer>
      <Answer ID="1459" Valid="false" Position="3"
Media="/bgmain/Image.ashx?ID=114">txt</Answer>
      <Answer ID="1460" Valid="false" Position="4"
Media="/bgmain/Image.ashx?ID=115">txt</Answer>
    </Answers>
  </Question>
-----

So from this, I need to:
1. Find any Media attribute, nested or otherwise (e.g. in E4X,
questionXML..@Media)
2. Store each of these to download them
3. Replace the values in the XML with local path equivalents, e.g.
"images/image_@{imageID}.jpg"
4. Go through stored list, download the images and put them in the right
place (I know how to do that bit with copy url)

*/


a quick response to get you going =

<project name="bla" default="main" basedir=".">
  <!-- Import XMLTask -->
  <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask"/>

  <target name="depends">
    <xmltask source="xpathtest.xml">
      <call path="/Question/Answers/*" target="foo">
        <param name="img" path="@Media" />
      </call>
    </xmltask>
  </target>

  <target name="foo">

<!-- do something with img or write to a file like that, there may be
another way with xmltask buffer too, never used it, see xmltask docs
-->
    <echo file="foo.txt" append="true">${img}${line.separator}</echo>
    <echo>Image = ${img}</echo>
  </target>

  <target name="xmlreplace">
    <xmltask source="xpathtest.xml" dest="xxxpathtest.xml" report="true">
      <regexp path="/Question/Answers/*/@Media"
              pattern="(.+\.)(.+=)(\d+)"
              replace="$1$3jpg"
      />
    </xmltask>
  </target>

  <target name="main" depends="depends,xmlreplace"/>
</project>


Regards, Gilbert
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: RegExp help needed!

Posted by Jowie <jo...@mac.com>.
Hi Gilbert,

Thanks very much for taking the time to help me out. Unfortunately I've not
used Xpath before and don't really have time to learn :( but if I give you
an example of my XML, could you perhaps point me in the right direction?
Here is an example:

------
  <Question ID="531" Subject="L" Category="Punc" Presentation="PT01"
Engine="MC01" Body="test" Media="/bgmain/Image.ashx?ID=12">
    <TipID/>
    <Answers>
      <Answer ID="1457" Valid="false" Position="1"
Media="/bgmain/Image.ashx?ID=112">txt</Answer>
      <Answer ID="1458" Valid="true" Position="2"
Media="/bgmain/Image.ashx?ID=113">txt</Answer>
      <Answer ID="1459" Valid="false" Position="3"
Media="/bgmain/Image.ashx?ID=114">txt</Answer>
      <Answer ID="1460" Valid="false" Position="4"
Media="/bgmain/Image.ashx?ID=115">txt</Answer>
    </Answers>
  </Question>
-----

So from this, I need to:
1. Find any Media attribute, nested or otherwise (e.g. in E4X,
questionXML..@Media)
2. Store each of these to download them
3. Replace the values in the XML with local path equivalents, e.g.
"images/image_@{imageID}.jpg"
4. Go through stored list, download the images and put them in the right
place (I know how to do that bit with copy url)

Many thanks!

:-Joe


Rebhan, Gilbert wrote:
> 
> 
> hit the send button to soon, should be =
> 
> so you would go like that =
> 
> <xmltask source="${local.path}GetAllQuestions.xml">
>  <call path="yourxpathexpression" target="yourdownloadtarget">
>   
>    ...
>   </call>
> </xmltask>
> 
> 
> 
> 
> 
> Regards, Gilbert
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/RegExp-help-needed%21-tp26676257p26676679.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: RegExp help needed!

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
 
 
-----Original Message-----
From: Jowie [mailto:joe.nash@mac.com] 
Sent: Monday, December 07, 2009 1:02 PM
To: user@ant.apache.org
Subject: RegExp help needed!

/*
so you would go like that =

<xmltask source="">
 <call path="//module/*[liefertyp/text()='build']" target="yourdownloadtarget">
  <param name..." path="..."/>
   ...
  </call>
</xmltask>
/*

hit the send button to soon, should be =

so you would go like that =

<xmltask source="${local.path}GetAllQuestions.xml">
 <call path="yourxpathexpression" target="yourdownloadtarget">
  <param name..." path="..."/>
   ...
  </call>
</xmltask>





Regards, Gilbert

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: RegExp help needed!

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
 
-----Original Message-----
From: Jowie [mailto:joe.nash@mac.com] 
Sent: Monday, December 07, 2009 1:02 PM
To: user@ant.apache.org
Subject: RegExp help needed!

/*
Hi all,

I'm fumbling my way around Ant and finding the help on the web really
confusing. I am using Ant simply as a macro copy/download/find-replace
utility and am an ActionScript programmer, not a Java one.

Anyway... There's one bit I'm stuck on and really need your help please!

I have used Ant to download an XML file and store it locally. I now need a
way of going through the XML, finding all the image URL attributes,
downloading those images and replacing all the URLs in the XML to local
relative paths. So far, all I have is:

		<loadfile property="questions" srcFile="${local.path}GetAllQuestions.xml"
/>
		<propertyregex input="${questions}" property="questions.output"
regexp="Media=&quot;(.*?)&quot;" select="\1" global="true" />
		<echo message="${questions.output}" />

*/

regexp for xml or html is not recommended, better use xmltask and the power of xpath =

xmltask
http://www.oopsconsultancy.com/software/xmltask/

xpath
http://www.w3schools.com/Xpath/
http://www.zvon.org/xxl/XPathTutorial/General/examples.html


so you would go like that =

<xmltask source="">
 <call path="//module/*[liefertyp/text()='build']" target="yourdownloadtarget">
  <param name..." path="..."/>
   ...
  </call>
</xmltask>


you may post a snippet of your xml file to get the right xpath expression.


Regards, Gilbert




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org