//____________________________________________________________________________
/*!

\class    genie::XmlParserUtils

\brief    XML document parsing utilities.

\author   Costas Andreopoulos <costas.andreopoulos \at stfc.ac.uk>
          STFC, Rutherford Appleton Laboratory

\created  May 04, 2004
 
\cpright  Copyright (c) 2003-2009, GENIE Neutrino MC Generator Collaboration
          For the full text of the license visit http://copyright.genie-mc.org
          or see $GENIE/LICENSE
*/
//____________________________________________________________________________

#ifndef _XML_PARSER_UTILS_H_
#define _XML_PARSER_UTILS_H_

#include <string>

#include "libxml/parser.h"
#include "libxml/xmlmemory.h"

#include "Utils/StringUtils.h"

using std::string;

namespace genie {

class XmlParserUtils {

public:

  static string TrimSpaces(xmlChar * xmls)
  {
   // trim the leading/trailing spaces from an parsed xml string like in:
   //
   // "      I am a string with lots of spaces      " ---->
   //                                  "I am a string with lots of spaces"
   //
   // In this method, "\n" is treated as 'empty space' so as to trim not only
   // empty spaces in the line that contains the string but also all leading
   // and trailing empty lines

    string str = string( (const char *) xmls );

    return utils::str::TrimSpaces(str);
  }
  //_________________________________________________________________________
  static string GetAttribute(xmlNodePtr xml_cur, string attr_name)
  {
   xmlChar * xmls = xmlGetProp(xml_cur, (const xmlChar *) attr_name.c_str());

   string str = TrimSpaces(xmls);

   xmlFree(xmls);

   return str;
  }
  //_________________________________________________________________________
};

}         // namespace
#endif    // _XML_PARSER_UTILS_H_

