I am new to Ant. I am trying to determine whether an attribute is set or not in an xml file.
Below is the xml file I am dealing with [config.xml]
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE LabelConfig SYSTEM "labelConfig.dtd"> <LabelConfig enabled="false"> </LabelConfig>
I want to check if above file (config.xml) has LabelConfig enabled or not, i.e I want to get and check the value of enabled attribute.
Here is what I’ve tried but is not full proof. I wrote below target
<target name="read_config">
<loadfile property="msg" srcFile="d:/conf/config.xml" />
<if>
<or>
<contains string="${msg}" substring="LabelConfig enabled='false'" />
<contains string="${msg}" substring='LabelConfig enabled="false"' />
</or>
<then>
<echo>LabelConfig is enabled</echo>
</then>
<else>
<echo>LabelConfig is not enabled</echo>
</else>
</if>
</target>
This has a drawback of not working if multiple spaces occur in between attribute and tag.
Can anyone please guide me to a better way?
Thanks in advance,
Vaman
Have a look at the
xmlpropertytask: http://ant.apache.org/manual/Tasks/xmlproperty.html