2012-08-23 62 views
1

可能重複:
Pass semicolon in Ant as a parameter解析「;」與Ant腳本分離XML值

我必須從這個XML屬性標記

<databases key="Test" type=".configdb"> 
     <dbname>test</dbname> 
     <driver type=".dbdriver"> 
     <attributes>localhost;1521;XE;false</attributes> 
     <driverType>Oracle thin</driverType> 
     </driver> 
     <password>965449DE3DB045FE</password> 
     <user>test</user> 
    </databases> 

與Ant腳本閱讀本XE

看過很多想法;但似乎都是漫長的道路,甚至不需要確切的目的地。

在此先感謝。

回答

2

假設您在某個resource.xml中有此標籤。您可以使用scriptdef代碼段,使用Ant的javascript引擎解析XE

的build.xml

<target name="something" ... 
... 
    <scriptdef language="javascript" name="split"> 
    <attribute name="input"/> 
    <attribute name="output"/> 
    values = attributes.get("input"); 
    project.setProperty(attributes.get("output"), values.split(";")[2]); 
    </scriptdef> 

    <xmlproperty file="resource.xml"/> 
    <echo message="Original: ${databases.driver.attributes}"/> 
    <split input="${databases.driver.attributes}" output="result" /> 
    <echo message="Split: ${result}"/> 
... 
</target> 


當運行這個任務,你會得到:

something: 
[xmlproperty] Loading /home/code/resource.xml 
    [echo] Original: localhost;1521;XE;false 
    [echo] Split: XE