开发者

Copy non xml resources

I need to process xml file a开发者_如何转开发nd copy some resources that occur in it

Input resources

-inputFolder
  -1.xml
  -1.jpg
  -2.jpg

Content of 1.xml:

<links>
   <link ref="1.jpg"/>
   <link ref="2.jpg"/>
</links>

Output resources

-outputFolder
  -1.xml.out
  -1.jpg
  -2.jpg

Content of 1.xml.out:

<links_new>
  <link_new ref_new="1.jpg"/>
  <link_new ref_new="2.jpg"/>
</links_new>

Thus I want to copy 1.jpg and 2.jpg, Is it possible?


You can use XML starlet command tool to parse xml files.

To copy 1.jpg and 2.jpg use the following command (works on unix or cygwin):

xml sel -t -m "/links/link/@ref" -v '.' -o ';' 1.xml | xargs -d';' -I {} cp /input/path/{} /output/path/

The command

xml sel -t -m "/links/link/@ref" -v '.' -o ';' 1.xml

selects all jpg files and separates them by ';'.

Then xargs parses the input and pass it to cp which copies files to the destination directory.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜