Insert XML element in xml document using Ant

前端 未结 1 1338
悲&欢浪女
悲&欢浪女 2021-01-25 11:26

I want to insert one xml element in xml document :-

Input XML:-

    

        
相关标签:
1条回答
  • 2021-01-25 12:12

    To get <insert> to work, explicitly refer to the namespace in the element. Also <insert>, by default, puts new elements under existing ones. The code below changes the default to after.

    <xmltask source="abc.xml" dest="abc.xml">
        <insert path="//*[local-name()='resourceTypes']" position="after"> <![CDATA[
            <xt:resourceTypes xmlns:xt="http://www.efg.com">bcd</xt:resourceTypes>
        ]]>
        </insert>
    </xmltask>
    

    The resulting XML, based on the XML in the question:

    <?xml version="1.0" encoding="utf-8" standalone="no"?>
    <cus:try xmlns:cus="http://www.abc.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xt="http://www.efg.com">
      <cus:trying>
        <cus:query>
          <xt:resourceTypes>abc</xt:resourceTypes>
    <xt:resourceTypes>bcd</xt:resourceTypes>
          <xt:envValueTypes>def</xt:envValueTypes>
        </cus:query>
      </cus:trying>
    </cus:try>
    
    0 讨论(0)
提交回复
热议问题