/* gstreamermm - a C++ wrapper for gstreamer
 *
 * Copyright 2008 The gstreamermm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <gst/gstxml.h>
#include <gstreamermm/element.h>

_PINCLUDE(glibmm/private/object_p.h)
_PINCLUDE(gstreamermm/private/object_p.h)

namespace Gst
{

xmlDocPtr XML::write(const Glib::RefPtr<const Gst::Element>& element)
{
  return gst_xml_write(const_cast<GstElement*>(element->gobj()));
}

void XML::write_to_stream(const Glib::RefPtr<const Gst::Element>& element, std::ostream& out)
{
  xmlDocPtr xmlDoc = write(element);
  xmlpp::Node rootNode(xmlDocGetRootElement(xmlDoc));

  xmlpp::Document doc;
  doc.create_root_node_by_import(&rootNode);
  doc.write_to_stream_formatted(out);

  xmlFreeDoc(xmlDoc);
}

bool XML::parse_memory(const std::string& buffer, const Glib::ustring& root)
{
  return gst_xml_parse_memory(this->gobj(),(guchar*)(buffer.c_str()), buffer.size(), root.c_str());
}

} //namespace Gst
