简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM