You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Alpesh Vesuwala <al...@yahoo.co.in> on 2008/07/25 11:36:57 UTC

How to read an XML file and extract values for the attributes using ANT script

Hello Friends,

I have an XML file to read from it and extract values of some attributes.
These extracted values can further processed by the ANT script.

The Sample XML File is:

<TITLE>
	<ABC>abc</ABC>
	<XYZ>xyz</XYZ>
</TITLE>

I want to extract 'abc' and 'xyz' from this sample code. Please help me out,
how can I do that?

Thanks Alpesh
-- 
View this message in context: http://www.nabble.com/How-to-read-an-XML-file-and-extract-values-for-the-attributes-using-ANT-script-tp18648408p18648408.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: How to read an XML file and extract values for the attributes using ANT script

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


-----Original Message-----
From: Alpesh Vesuwala [mailto:alpeshvesuwala@yahoo.co.in] 
Sent: Friday, July 25, 2008 11:37 AM
To: user@ant.apache.org
Subject: How to read an XML file and extract values for the attributes
using ANT script

/*
I have an XML file to read from it and extract values of some
attributes.
These extracted values can further processed by the ANT script.
*/

use the xmltask =
http://www.oopsconsultancy.com/software/xmltask/

xpath knowledge advantageous


Regards, Gilbert

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


Re: How to read an XML file and extract values for the attributes using ANT script

Posted by Brian Agnew <br...@oopsconsultancy.com>.
XMLTask can do this.

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

<xmltask source="source.xml">
<copy path="/TITLE/ABC/text()" property="prop1"/>
<copy path="/TITLE/XYZ/text()" property="prop2"/>
</xmltask>

will copy the values into the properties prop1/prop2

Brian


On Fri, July 25, 2008 10:36, Alpesh Vesuwala wrote:
>
> Hello Friends,
>
> I have an XML file to read from it and extract values of some attributes.
> These extracted values can further processed by the ANT script.
>
> The Sample XML File is:
>
> <TITLE>
> 	<ABC>abc</ABC>
> 	<XYZ>xyz</XYZ>
> </TITLE>
>
> I want to extract 'abc' and 'xyz' from this sample code. Please help me
> out,
> how can I do that?
>
> Thanks Alpesh
> --
> View this message in context:
> http://www.nabble.com/How-to-read-an-XML-file-and-extract-values-for-the-attributes-using-ANT-script-tp18648408p18648408.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
>


-- 
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: How to read an XML file and extract values for the attributes using ANT script

Posted by "Muller, Anthony" <an...@sap.com>.
I remember you can't do this directly with Ant, but you have to use an extension...

Look at: XMLTask (xmltask-v1.15.1.jar)

Anthony MÜLLER



-----Original Message-----
From: Alpesh Vesuwala [mailto:alpeshvesuwala@yahoo.co.in] 
Sent: Friday, July 25, 2008 11:37 AM
To: user@ant.apache.org
Subject: How to read an XML file and extract values for the attributes using ANT script


Hello Friends,

I have an XML file to read from it and extract values of some attributes.
These extracted values can further processed by the ANT script.

The Sample XML File is:

<TITLE>
	<ABC>abc</ABC>
	<XYZ>xyz</XYZ>
</TITLE>

I want to extract 'abc' and 'xyz' from this sample code. Please help me out,
how can I do that?

Thanks Alpesh
-- 
View this message in context: http://www.nabble.com/How-to-read-an-XML-file-and-extract-values-for-the-attributes-using-ANT-script-tp18648408p18648408.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


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


Re: How to read an XML file and extract values for the attributes using ANT script

Posted by Alpesh Vesuwala <al...@yahoo.co.in>.
SUPERB =)

I was trying,
        <call path="//TITLE" >
		/ :rules: XYZ/text()"/>
		/ :rules: ABC/text()"/>
                <actions>
			<echo>@{xyz} = @{abc}</echo>
                </actions>
        </call>

Thanks a lot,
Alpesh
-- 
View this message in context: http://www.nabble.com/How-to-read-an-XML-file-and-extract-values-for-the-attributes-using-ANT-script-tp18648408p18752935.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: How to read an XML file and extract values for the attributes using ANT script

Posted by Brian Agnew <br...@oopsconsultancy.com>.
Well, that's slightly different. The follwoing will illustrate what you
need..

<xmltask source="title.xml">
        <call path="//TITLE" >
		<param name="xyz" path="XYZ/text()"/>
		<param name="abc" path="ABC/text()"/>
                <actions>
			<echo>@{xyz} = @{abc}</echo>
                </actions>
        </call>
</xmltask>

Brian

On Thu, July 31, 2008 10:21, Alpesh Vesuwala wrote:
>
> Hi,
>
> Thanks for your quick response.
> The solution is fine but not working when my XML file looks like this:
>
> <TITLE>
>      <XYZ>123</XYZ>
>      <ABC>456</ABC>
> </TITLE>
> <TITLE>
>      <XYZ>987</XYZ>
>      <ABC>654</ABC>
> </TITLE>
> <TITLE>
>      <XYZ>147</XYZ>
>      <ABC>258</ABC>
> </TITLE>
>
> Thanks and Regards,
> Alpesh
>
>
> You should be able to do that with a param to call. i.e. identify the node
> you're interested in with:
>
> <call path="....">
>
> and specify a param:
>
>  questions, which may
> be a better forum going forwards.
>
> Brian
> --
> View this message in context:
> http://www.nabble.com/How-to-read-an-XML-file-and-extract-values-for-the-attributes-using-ANT-script-tp18648408p18750721.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
>


-- 
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: How to read an XML file and extract values for the attributes using ANT script

Posted by Alpesh Vesuwala <al...@yahoo.co.in>.
Hi,

Thanks for your quick response.
The solution is fine but not working when my XML file looks like this:

<TITLE>
     <XYZ>123</XYZ>
     <ABC>456</ABC>
</TITLE>
<TITLE>
     <XYZ>987</XYZ>
     <ABC>654</ABC>
</TITLE>
<TITLE>
     <XYZ>147</XYZ>
     <ABC>258</ABC>
</TITLE>

Thanks and Regards,
Alpesh


You should be able to do that with a param to call. i.e. identify the node
you're interested in with:

<call path="....">

and specify a param:

 questions, which may
be a better forum going forwards.

Brian
-- 
View this message in context: http://www.nabble.com/How-to-read-an-XML-file-and-extract-values-for-the-attributes-using-ANT-script-tp18648408p18750721.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: How to read an XML file and extract values for the attributes using ANT script

Posted by Brian Agnew <br...@oopsconsultancy.com>.
You should be able to do that with a param to call. i.e. identify the node
you're interested in with:

<call path="....">

and specify a param:

<param path="following-sibling:...

Note there's a dedicated mailing list for <xmltask> questions, which may
be a better forum going forwards.

Brian

On Thu, July 31, 2008 08:46, Alpesh Vesuwala wrote:
>
> Hey one more twist has come with my requirement.
>
> the above solution of xmltask requires separate 'call' to loop through
> 'XYZ'
> and 'ABC'
> Resulting in, I have first all the values of XYZ and then for ABC. and I
> want values for both together.
>
> e.g.
> <TITLE>
>         <ABC>abc</ABC>
>         <XYZ>xyz</XYZ>
>
>         <ABC>123</ABC>
>         <XYZ>456</XYZ>
>
>         ...
>         ...
>
> </TITLE>
>
> The 'call' should fetch values for both ABC and XYZ at a same time %-|
>
> Thanks,
> Alpesh
> --
> View this message in context:
> http://www.nabble.com/How-to-read-an-XML-file-and-extract-values-for-the-attributes-using-ANT-script-tp18648408p18749436.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
>


-- 
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: How to read an XML file and extract values for the attributes using ANT script

Posted by Alpesh Vesuwala <al...@yahoo.co.in>.
Hey one more twist has come with my requirement.

the above solution of xmltask requires separate 'call' to loop through 'XYZ'
and 'ABC'
Resulting in, I have first all the values of XYZ and then for ABC. and I
want values for both together.

e.g.
<TITLE>
        <ABC>abc</ABC>
        <XYZ>xyz</XYZ>

        <ABC>123</ABC>
        <XYZ>456</XYZ>

        ...
        ...

</TITLE>

The 'call' should fetch values for both ABC and XYZ at a same time %-|

Thanks,
Alpesh
-- 
View this message in context: http://www.nabble.com/How-to-read-an-XML-file-and-extract-values-for-the-attributes-using-ANT-script-tp18648408p18749436.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: How to read an XML file and extract values for the attributes using ANT script

Posted by Alpesh Vesuwala <al...@yahoo.co.in>.
Thanks Brian,

It works as per what I expected. :drunk:

Thank you very much,
Alpesh
-- 
View this message in context: http://www.nabble.com/How-to-read-an-XML-file-and-extract-values-for-the-attributes-using-ANT-script-tp18648408p18732640.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: How to read an XML file and extract values for the attributes using ANT script

Posted by Brian Agnew <br...@oopsconsultancy.com>.
You can use <xmltask> and its <call> function. e.g.

<call path="/TITLE/XYZ">
  <param name="val" path="text()"/>

  <actions>
    <echo>val = @{val}</echo>
  </actions>
</call>

and some additional XPath magic ('following-sibling' or similar) to get
the following XYZ node (not tried this, though! You may need an XPath
tutorial like http://www.zvon.org/xxl/XPathTutorial/General/examples.html
)

Brian

On Wed, July 30, 2008 12:07, Alpesh Vesuwala wrote:
>
> Thank you all for your valuable inputs.
>
> I tried 'xmltask' for my solution and it is working really well. :jumping:
> I really appreciate your kind responses. =)
>
> Please clarify one more doubt,
> I may have multiple tags and they can be random.
>
> For example,
>
> <TITLE>
>         <ABC>abc</ABC>
>         <XYZ>xyz</XYZ>
>
>         <ABC>123</ABC>
>         <XYZ>456</XYZ>
>
>         ...
>         ...
>
> </TITLE>
>
> How can I do loop through each tags, like for and while loop in java :-((
>
> Thanks,
> Alpesh
> --
> View this message in context:
> http://www.nabble.com/How-to-read-an-XML-file-and-extract-values-for-the-attributes-using-ANT-script-tp18648408p18730889.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
>


-- 
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: How to read an XML file and extract values for the attributes using ANT script

Posted by Alpesh Vesuwala <al...@yahoo.co.in>.
Thank you all for your valuable inputs.

I tried 'xmltask' for my solution and it is working really well. :jumping:
I really appreciate your kind responses. =)

Please clarify one more doubt,
I may have multiple tags and they can be random.

For example,

<TITLE>
        <ABC>abc</ABC>
        <XYZ>xyz</XYZ>

        <ABC>123</ABC>
        <XYZ>456</XYZ>

        ...
        ...

</TITLE>

How can I do loop through each tags, like for and while loop in java :-((

Thanks,
Alpesh
-- 
View this message in context: http://www.nabble.com/How-to-read-an-XML-file-and-extract-values-for-the-attributes-using-ANT-script-tp18648408p18730889.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: How to read an XML file and extract values for the attributes using ANT script

Posted by Stojanov Alexej <Al...@bitmarck.de>.
Better:  http://ant.apache.org/manual/CoreTasks/xmlproperty.html

-------
<project name="xmlProperty" basedir="." default="main">
    <target name="main">
        <xmlproperty file="C:/myTITLE.xml" prefix="myFileContent"/>
        <echo message=" ABC = ${myFileContent.TITLE.ABC}"/>
        <echo message=" XYZ = ${myFileContent.TITLE.XYZ}"/>
    </target>
</project>
-------

Alexej Stojanov

-----Original Message-----
From: stguitar@mac.com [mailto:stguitar@mac.com] 
Sent: Friday, July 25, 2008 3:24 PM
To: Ant Users List
Subject: Re: How to read an XML file and extract values for the
attributes using ANT script

FYI. You could read the file into a property and use regular  
expressions. Since it's XML the patterns would not be too difficult

Sent from my iPhone

On Jul 25, 2008, at 4:36 AM, Alpesh Vesuwala  
<al...@yahoo.co.in> wrote:

>
> Hello Friends,
>
> I have an XML file to read from it and extract values of some  
> attributes.
> These extracted values can further processed by the ANT script.
>
> The Sample XML File is:
>
> <TITLE>
>    <ABC>abc</ABC>
>    <XYZ>xyz</XYZ>
> </TITLE>
>
> I want to extract 'abc' and 'xyz' from this sample code. Please help  
> me out,
> how can I do that?
>
> Thanks Alpesh
> -- 
> View this message in context:
http://www.nabble.com/How-to-read-an-XML-file-and-extract-values-for-the
-attributes-using-ANT-script-tp18648408p18648408.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
>

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



***********************************************************************

Die Information in dieser email ist vertraulich und ist ausschliesslich 
fuer den/die benannten Adressaten bestimmt. Ein Zugriff auf diese
email durch andere Personen als den/die benannten Adressaten ist
nicht gestattet. Sollten Sie nicht der benannte Adressat sein, loeschen
Sie bitte diese email. 

***********************************************************************

BITMARCK Software GmbH
Paul-Klinger-Strasse 15, 45127 Essen 
 
Amtsgericht Essen HRB 20680
Geschaeftsfuehrer: Frank Krause, Andreas Prenneis


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


Re: How to read an XML file and extract values for the attributes using ANT script

Posted by Steven Guitar <st...@mac.com>.
FYI. You could read the file into a property and use regular  
expressions. Since it's XML the patterns would not be too difficult

Sent from my iPhone

On Jul 25, 2008, at 4:36 AM, Alpesh Vesuwala  
<al...@yahoo.co.in> wrote:

>
> Hello Friends,
>
> I have an XML file to read from it and extract values of some  
> attributes.
> These extracted values can further processed by the ANT script.
>
> The Sample XML File is:
>
> <TITLE>
>    <ABC>abc</ABC>
>    <XYZ>xyz</XYZ>
> </TITLE>
>
> I want to extract 'abc' and 'xyz' from this sample code. Please help  
> me out,
> how can I do that?
>
> Thanks Alpesh
> -- 
> View this message in context: http://www.nabble.com/How-to-read-an-XML-file-and-extract-values-for-the-attributes-using-ANT-script-tp18648408p18648408.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
>

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