// Comile this like so:
// g++ libxmlpp_formatted.cc `pkg-config libxml++-2.6 --cflags --libs`
// and then check result.xml.

#include <iostream>
#include <libxml++/libxml++.h>

int main()
{
  try
  {
    xmlpp::DomParser parser;
    parser.parse_file("test.xml");
    if(parser)
    {
      xmlpp::Document *doc = parser.get_document();
      xmlpp::Node *root = doc->get_root_node();
      xmlpp::Element *tmp_elem = root->add_child("newnode00");
      xmlpp::Node *tmp_node = dynamic_cast<xmlpp::Node*>(tmp_elem);

      tmp_elem = tmp_node->add_child("childnode01");
      tmp_elem->set_child_text("text 0.1");
      tmp_elem = tmp_node->add_child("childnode02");
      tmp_elem->set_child_text("text 0.2");

      doc->write_to_file_formatted("result.xml");
    }
    else
      std::cout << "Error reading test.xml" << std::endl;;
  }
  catch(const std::exception &ex)
  {
    std::cout << "Exception caught: " << ex.what() << std::endl;
  }

  return 0;
}

