body file control
{
  inputs => { "$(sys.policy_entry_dirname)/../common.cf.sub" };
}

bundle common testcase
{
  vars:
    "filename" string => "$(this.promise_filename)";
}

bundle agent setup
{
  files:
    "$(G.testfile)"
      edit_xml => xml_insert_tree_nopath("<Root/>"),
      create => "true";
}

bundle agent main
{
  vars:
    "xml1" string => "<x foo='bar'>y</x>";
    "xml2" string => "<a><b><c>text content</c></b></a>";

  files:
    "$(G.testfile)" edit_xml => xml_insert_tree("$(xml1)", "//Root");
}

bundle agent teardown
{
  reports:
    "Edited file has contents: " printfile => my_cat($(G.testfile));
}

body printfile my_cat(file)
# @brief Report the contents of a file
# @param file The full path of the file to report
{
  file_to_print => "$(file)";
  number_of_lines => "inf";
}

bundle edit_xml xml_insert_tree_nopath(treestring)
{
  insert_tree:
    '$(treestring)';
}

bundle edit_xml xml_insert_tree(treestring, xpath)
{
  insert_tree:
    '$(treestring)' select_xpath => "$(xpath)";
}
