You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Rebhan, Gilbert" <Gi...@huk-coburg.de> on 2007/07/10 14:40:05 UTC
xmltask xpath bug ?!, buffer to property ?!
Hi,
i have a problem with xmltask 1.14 and xpath.
i want a nodelist as property.
the relevant xml section looks like that =
<module>
<modul.0>
<name>modul_A</name>
<label>020407_134553535</label>
<buildpossible>N</buildpossible>
</modul.0>
<modul.1>
<name>modul_B</name>
<label>to_be_build</label>
<buildpossible>J</buildpossible>
</modul.1>
</module>
with the xpath expression =
//module/*/name/text()
i expect to get the nodelist containing both modulnames
modul_A
modul_B
but with =
<xmltask source="props.xml">
<copy path="count(//module/*/name/text())" property="name.count"/>
<copy path="//module/*/name/text()" property="moduls.text"/>
</xmltask>
<echo>
$${name.count} = ${name.count}
$${moduls.text} = ${moduls.text}
</echo>
i get only =
[echo] ${name.count} = 2
[echo] ${moduls.text} = modul_A
Is that a bug or works as designed ?
i expected to get the nodelist with all matches
i believe it's because the property ${moduls.text} is set
at first match - which is modul_A - and the second match
get's not appended to that, because once set a (normal) property
is immutable in ant.
so i tried a buffer =
<target name="init">
<xmltask source="props.xml">
<copy path="count(//module/*/name/text())" property="name.count"/>
<copy path="//module/*/name/text()" buffer="moduls.text"
append="true"/>
<print buffer="moduls.text"/>
</xmltask>
that gives me =
[xmltask] { buffer 'moduls.text' output
[xmltask] modul_A
[xmltask] } buffer 'moduls.text' output
[xmltask] { buffer 'moduls.text' output
[xmltask] modul_B
[xmltask] } buffer 'moduls.text' output
so both modulnames are contained now, but how to get
that buffer in a property ?
Any ideas ?
Regards, Gilbert
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
RE: xmltask xpath bug ?!, buffer to property ?!
Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
Hi, Brian
-----Original Message-----
From: Brian Agnew [mailto:brian@oopsconsultancy.com]
Sent: Tuesday, July 10, 2007 3:02 PM
To: Ant Users List
Cc: xmltask-users@lists.sourceforge.net
Subject: Re: xmltask xpath bug ?!, buffer to property ?!
/*
(note: there's an XMLTask mailing list
xmltask-users@lists.sourceforge.net
which is more suitable for XMLTask-specific messages, but...)
*/
normally i have no problems with xmltask ;-) but thanks for the pointer
/*
I will have to check on property appends vs. buffer appends and what's
expected to work.
*/
i expect the whole nodelist in the property when there is more than 1
match
would be nice to have all matches (nodelist) as separated list, and
the separator may be set as attribute ( default ' , ' )
/*
Buffers are a better thing to copy/paste into (for many reasons I won't
go
into here). You can copy from a buffer to a property. Probably by doing
something like (warning - this is untested!)
<xmltask sourcebuffer="your buffer name">
<copy path="/" property="your property name">
....
*/
i tried that, but that gave me =
[xmltask] Cannot use multiple buffer nodes as an input source
[xmltask] at
com.oopsconsultancy.xmltask.ant.XmlTask$InputBuffer.getDocument(XmlTask.
java:254)
[xmltask] at
com.oopsconsultancy.xmltask.ant.XmlTask.execute(XmlTask.java:653)
seems like a problem when there are more matches ?!
/*
or similar. Perhaps you can forgo the additional <xmltask> invocation by
creating a dummy node in your real doc, pasting into that, copying into
a
property and then deleting the dummy node ?
*/
i just need to pull out several parts of a xmlproperty file and dump it
to a txtfile
as input for a shellscript so it's no editing of a xmlpropertyfile
If nothing else works i'll go via <script> task with ruby, here i get
all nodes as
array, i.e. =
require "rexml/document"
include REXML
...
names = XPath.match( doc, "//module/*/name")
File.open("Y:/demo.txt", "a") { |f|
names.each { |mname| f.print mname.text+"\r\n"}
}
Regards, Gilbert
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: xmltask xpath bug ?!, buffer to property ?!
Posted by Brian Agnew <br...@oopsconsultancy.com>.
Hi Gilbert -
(note: there's an XMLTask mailing list xmltask-users@lists.sourceforge.net
which is more suitable for XMLTask-specific messages, but...)
I will have to check on property appends vs. buffer appends and what's
expected to work. Note that properties are normally immutable, so I
suspect that (for whatever reason) XMLTask will set the property once to
the first match and not change it afterwards.
Buffers are a better thing to copy/paste into (for many reasons I won't go
into here). You can copy from a buffer to a property. Probably by doing
something like (warning - this is untested!)
<xmltask sourcebuffer="your buffer name">
<copy path="/" property="your property name">
....
or similar. Perhaps you can forgo the additional <xmltask> invocation by
creating a dummy node in your real doc, pasting into that, copying into a
property and then deleting the dummy node ?
Brian
On Tue, July 10, 2007 13:40, Rebhan, Gilbert wrote:
>
> Hi,
>
> i have a problem with xmltask 1.14 and xpath.
> i want a nodelist as property.
>
> the relevant xml section looks like that =
>
> <module>
> <modul.0>
> <name>modul_A</name>
> <label>020407_134553535</label>
> <buildpossible>N</buildpossible>
> </modul.0>
> <modul.1>
> <name>modul_B</name>
> <label>to_be_build</label>
> <buildpossible>J</buildpossible>
> </modul.1>
> </module>
>
> with the xpath expression =
>
> //module/*/name/text()
>
> i expect to get the nodelist containing both modulnames
>
> modul_A
> modul_B
>
>
> but with =
>
> <xmltask source="props.xml">
> <copy path="count(//module/*/name/text())" property="name.count"/>
> <copy path="//module/*/name/text()" property="moduls.text"/>
> </xmltask>
> <echo>
> $${name.count} = ${name.count}
> $${moduls.text} = ${moduls.text}
> </echo>
>
> i get only =
>
> [echo] ${name.count} = 2
> [echo] ${moduls.text} = modul_A
>
> Is that a bug or works as designed ?
> i expected to get the nodelist with all matches
>
> i believe it's because the property ${moduls.text} is set
> at first match - which is modul_A - and the second match
> get's not appended to that, because once set a (normal) property
> is immutable in ant.
>
> so i tried a buffer =
>
> <target name="init">
> <xmltask source="props.xml">
> <copy path="count(//module/*/name/text())" property="name.count"/>
> <copy path="//module/*/name/text()" buffer="moduls.text"
> append="true"/>
> <print buffer="moduls.text"/>
> </xmltask>
>
> that gives me =
>
> [xmltask] { buffer 'moduls.text' output
> [xmltask] modul_A
> [xmltask] } buffer 'moduls.text' output
> [xmltask] { buffer 'moduls.text' output
> [xmltask] modul_B
> [xmltask] } buffer 'moduls.text' output
>
> so both modulnames are contained now, but how to get
> that buffer in a property ?
>
> Any ideas ?
>
> Regards, Gilbert
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
--
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