如何使用命令行工具将元素及其具有的所有内容从XML文件复制到另一个文件?
例如,有一种使用诸如“从file-x.note复制到file-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