开发者

How to check for attribute value in an XML file using Ant

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 xmlproperty task: http://ant.apache.org/manual/Tasks/xmlproperty.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜