Sophie

Sophie

distrib > Mandriva > 10.0-com > i586 > by-pkgid > f0a9f2b9c81d34eadc43f527947c0b70 > files > 182

libgstreamer0.7-devel-0.7.4-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML
><HEAD
><TITLE
>Adding custom XML tags into the core XML data</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="Loading a GstElement from an XML file"
HREF="section-xml-load.html"><LINK
REL="NEXT"
TITLE="Appendices"
HREF="part-appendices.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="section-xml-load.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="part-appendices.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="section-xml-custom"
>31.3. Adding custom XML tags into the core XML data</A
></H1
><P
>&#13;      It is possible to add custom XML tags to the core XML created with
      gst_xml_write. This feature can be used by an application to add more
      information to the save plugins. The editor will for example insert
      the position of the elements on the screen using the custom XML tags.
    </P
><P
>&#13;      It is strongly suggested to save and load the custom XML tags using
      a namespace. This will solve the problem of having your XML tags 
      interfere with the core XML tags.
    </P
><P
>&#13;      To insert a hook into the element saving procedure you can link
      a signal to the GstElement using the following piece of code:
    </P
><PRE
CLASS="programlisting"
>&#13;xmlNsPtr ns;

  ...
  ns = xmlNewNs (NULL, "http://gstreamer.net/gst-test/1.0/", "test");
    ...
  thread = gst_element_factory_make ("thread", "thread");
  g_signal_connect (G_OBJECT (thread), "object_saved", 
  		     G_CALLBACK (object_saved), g_strdup ("decoder thread"));
    ...
    </PRE
><P
>&#13;      When the thread is saved, the object_save method will be called. Our example
      will insert a comment tag:
    </P
><PRE
CLASS="programlisting"
>&#13;static void
object_saved (GstObject *object, xmlNodePtr parent, gpointer data)
{
  xmlNodePtr child;

  child = xmlNewChild (parent, ns, "comment", NULL);
  xmlNewChild (child, ns, "text", (gchar *)data);
}
    </PRE
><P
>&#13;      Adding the custom tag code to the above example you will get an XML file
      with the custom tags in it. Here's an excerpt:
    </P
><PRE
CLASS="programlisting"
>&#13;          ...
        &#60;gst:element&#62;
          &#60;gst:name&#62;thread&#60;/gst:name&#62;
          &#60;gst:type&#62;thread&#60;/gst:type&#62;
          &#60;gst:version&#62;0.1.0&#60;/gst:version&#62;
	  ...
        &#60;/gst:children&#62;
        &#60;test:comment&#62;
          &#60;test:text&#62;decoder thread&#60;/test:text&#62;
        &#60;/test:comment&#62;
      &#60;/gst:element&#62;
          ...
    </PRE
><P
>&#13;      To retrieve the custom XML again, you need to attach a signal to 
      the GstXML object used to load the XML data. You can then parse your
      custom XML from the XML tree whenever an object is loaded.
    </P
><P
>&#13;      We can extend our previous example with the following piece of
      code.
    </P
><PRE
CLASS="programlisting"
>&#13;  xml = gst_xml_new ();

  g_signal_connect (G_OBJECT (xml), "object_loaded", 
  		     G_CALLBACK (xml_loaded), xml);

  ret = gst_xml_parse_file (xml, "xmlTest.gst", NULL);
  g_assert (ret == TRUE);
    </PRE
><P
>&#13;      Whenever a new object has been loaded, the xml_loaded function will
      be called. This function looks like:
    </P
><PRE
CLASS="programlisting"
>&#13;static void
xml_loaded (GstXML *xml, GstObject *object, xmlNodePtr self, gpointer data)
{
  xmlNodePtr children = self-&#62;xmlChildrenNode;

  while (children) {
    if (!strcmp (children-&#62;name, "comment")) {
      xmlNodePtr nodes = children-&#62;xmlChildrenNode;

      while (nodes) {
        if (!strcmp (nodes-&#62;name, "text")) {
          gchar *name = g_strdup (xmlNodeGetContent (nodes));
          g_print ("object %s loaded with comment '%s'\n",
                   gst_object_get_name (object), name);
        }
        nodes = nodes-&#62;next;
      }
    }
    children = children-&#62;next;
  }
}
    </PRE
><P
>&#13;      As you can see, you'll get a handle to the GstXML object, the 
      newly loaded GstObject and the xmlNodePtr that was used to create
      this object. In the above example we look for our special tag inside
      the XML tree that was used to load the object and we print our
      comment to the console.
    </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="section-xml-load.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="part-appendices.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Loading a GstElement from an XML file</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"
>Appendices</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>