我正在尝试使用 xmltask(ANT 脚本)替换 xml 字段值。但如果 xml 元素为空,它不会替换该值。
例如 :
<Mydoc>
<doc>
<docname>abc.txt</docname>
<doclocation>xyz</doclocation>
</doc>
<doc>
<docname>mmm.txt</docname>
<doclocation></doclocation>
</doc>
</Mydoc>
in the above example i want to update the "doclocation" element if "docname" element is "mmm.txt"
用来实现它的脚本。
<xmltask dest="sample.xml">
<fileset file="sample.xml"/>
<replace
path="/Mydoc/doc[docname="mmm.txt"]/doclocation/text()"
withText="newURL"/>
</xmltask>
如果 'doclocation' 元素具有空值/无值,则上述代码不起作用。
这里需要做什么来处理空值并将其替换为新值?