簡體   English   中英

使用命令行將 XML 元素從一個文件復制到另一個文件

[英]Copying XML element from one file to another using command line

如何使用命令行工具將元素及其包含的任何內容從 XML 文件復制到另一個文件?

例如,有沒有辦法使用諸如“從文件-x.note 復制到文件-y.mynotes”之類的命令將下面文件 X 中的所有內容復制到文件 Y 中?

文件 X:

<?xml version="1.0" encoding="UTF-8"?>
<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>

文件 Y:

<?xml version="1.0" encoding="UTF-8"?>
<mynotes>

  <!-- The content of file X here -->

  <note>
    <to>Tove2</to>
    <from>Jani2</from>
    <heading>Reminder2</heading>
    <body>Don't forget me this weekend2!</body>
  </note>

  <note>
    <to>Tove3</to>
    <from>Jani3</from>
    <heading>Reminder3</heading>
    <body>Don't forget me this weekend!3</body>
  </note>

<mynotes>

這有點困難,但可以用 xidel 完成:

xidel  file_y.xml --xquery 'let $abc := (./mynotes/note) \
let $def := doc("file_x.xml")//*[1] return insert-before($abc, 0, $def)' --output-format xml

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM