nborpe
nborpe

Reputation: 209

How to read xml attribute value on apache ant?

I have an xml like below.

  <Students college="SGS">
     <Student id="001" name="ABC"/>
     <Student id="002" name="XYZ"/>
  <Students/>
  <Students college="SPM">
    <Student id="001" name="PQR"/>
    <Student id="002" name="LMN"/>
  <Students/>

and I want name of the student of the SGS college whose id is 001 using apache ant. So how can I get this without using extra jar like xmltask.jar etc

Upvotes: 1

Views: 1051

Answers (1)

M A
M A

Reputation: 72884

The simplest solution is to use XPath to get this information. In Ant there is no built-in task to fetch XML data using XPath expressions. You would need to use tasks provided in external libraries:

https://code.google.com/p/ant-xpath-task/wiki/Introduction

http://ant.apache.org/external.html

Upvotes: 2

Related Questions