<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >Loading a GstElement from an XML file</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="GStreamer Application Development Manual" HREF="index.html"><LINK REL="UP" TITLE="XML in GStreamer" HREF="chapter-xml.html"><LINK REL="PREVIOUS" TITLE="XML in GStreamer" HREF="chapter-xml.html"><LINK REL="NEXT" TITLE="Adding custom XML tags into the core XML data" HREF="section-xml-custom.html"></HEAD ><BODY CLASS="sect1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" ><SPAN CLASS="application" >GStreamer</SPAN > Application Development Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="chapter-xml.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Chapter 31. XML in <SPAN CLASS="application" >GStreamer</SPAN ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="section-xml-custom.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="section-xml-load" >31.2. Loading a GstElement from an XML file</A ></H1 ><P > Before an XML file can be loaded, you must create a GstXML object. A saved XML file can then be loaded with the gst_xml_parse_file (xml, filename, rootelement) method. The root element can optionally left NULL. The following code example loads the previously created XML file and runs it. </P ><PRE CLASS="programlisting" > #include <stdlib.h> #include <gst/gst.h> int main(int argc, char *argv[]) { GstXML *xml; GstElement *bin; gboolean ret; gst_init (&argc, &argv); xml = gst_xml_new (); ret = gst_xml_parse_file(xml, "xmlTest.gst", NULL); g_assert (ret == TRUE); bin = gst_xml_get_element (xml, "bin"); g_assert (bin != NULL); gst_element_set_state (bin, GST_STATE_PLAYING); while (gst_bin_iterate(GST_BIN(bin))); gst_element_set_state (bin, GST_STATE_NULL); exit (0); } </PRE ><P > gst_xml_get_element (xml, "name") can be used to get a specific element from the XML file. </P ><P > gst_xml_get_topelements (xml) can be used to get a list of all toplevel elements in the XML file. </P ><P > In addition to loading a file, you can also load a from a xmlDocPtr and an in memory buffer using gst_xml_parse_doc and gst_xml_parse_memory respectively. Both of these methods return a gboolean indicating success or failure of the requested action. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="chapter-xml.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="section-xml-custom.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >XML in <SPAN CLASS="application" >GStreamer</SPAN ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="chapter-xml.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Adding custom XML tags into the core XML data</TD ></TR ></TABLE ></DIV ></BODY ></HTML >