xpath - How to extend an XML File using ant xmltask by copying tags from a source-file to the dest-file in specific positions -


im trying create special web.xml local development.

i have tags stored in separate xml-file need selected , pasted specific positions inside final web.xml.

to achieve using copy , paste action in following manner:

<xmltask source="templates.xml">   <copy path="//data/init-param" buffer="initparambuffer"/> </xmltask>  <xmltask source="web.xml" dest="web.xml">   <paste path="//web-app/filter[contains(./filter-name,'myfilter')]                            /init-param[contains(./param-name,                                                 'myinitparameter')]"          position="after" buffer="initparambuffer"/> </xmltask> 

my intention gather init-param tags source file , paste them after tag selected in paste operation.

also part im selecting tag contains tag specified content using contains() function not working smoothly either.

maybe there better way form xpath expression...


update:

as have written before, not know best approach problem. have read possibility transform using stylesheets, since ant-xmltask promised more sleak sollution have tried first.

as far have come approach, possible insert/write tags web.xml using approach. have succeeded in inserting single init-param tags @ locations sligtly off, less complex expression:

<paste path="//web-app/filter[1]/init-param"              position="after" buffer="initparambuffer"/> 

so problem was: a: want select more 1 tag buffer b: want insert content of buffer after tag specified name (not index).

here example sources (templates.xml) insert web.xml:

<data>   <init-param>     <param-name>newparam1</param-name>     <param-value>1</param-value>   </init-param>   <init-param>     <param-name>newparam2</param-name>     <param-value>2</param-value>   </init-param> </data> 

here part of web.xml above section pasted:

<web-app>   <filter-mapping>     <filter-name>somefilter</filter-name>     <url-pattern>/somepath/*</url-pattern>   </filter-mapping>   <filter-mapping>     <filter-name>myfilter</filter-name>     <url-pattern>/mypath/*</url-pattern>   </filter-mapping>    <filter>     <filter-name>somefilter</filter-name>     <filter-class>foo.bar.somefilter</filter-class>     <init-param>       <param-name>someinitparameter</param-name>       <param-value>4711</param-value>     </init-param>   </filter>   <filter>     <filter-name>myfilter</filter-name>     <filter-class>foo.bar.myfilter</filter-class>     <init-param>       <param-name>myinitparameter</param-name>       <param-value>0815</param-value>     </init-param>   </filter> </web-app> 

and here result hope achieve:

<web-app>   <filter-mapping>     <filter-name>somefilter</filter-name>     <url-pattern>/somepath/*</url-pattern>   </filter-mapping>   <filter-mapping>     <filter-name>myfilter</filter-name>     <url-pattern>/mypath/*</url-pattern>   </filter-mapping>    <filter>     <filter-name>somefilter</filter-name>     <filter-class>foo.bar.somefilter</filter-class>     <init-param>       <param-name>someinitparameter</param-name>       <param-value>4711</param-value>     </init-param>   </filter>   <filter>     <filter-name>myfilter</filter-name>     <filter-class>foo.bar.myfilter</filter-class>     <init-param>       <param-name>myinitparameter</param-name>       <param-value>0815</param-value>     </init-param>     <init-param>       <param-name>newparam1</param-name>       <param-value>1</param-value>     </init-param>     <init-param>       <param-name>newparam2</param-name>       <param-value>2</param-value>     </init-param>   </filter> </web-app> 

use xpath or:

path|path

from:

<paste path="//web-app/filter[1]/init-param" position="after" buffer="initparambuffer"/> 

to:

<paste path="//web-app/filter[1]/init-param|//web-app/filter[2]/init-param" position="after" buffer="initparambuffer"/> 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -