added function gst_xml_write_file() which writes a nicely formatted and indented...
authorAndy Wingo <wingo@pobox.com>
Fri, 11 Jan 2002 01:48:17 +0000 (01:48 +0000)
committerAndy Wingo <wingo@pobox.com>
Fri, 11 Jan 2002 01:48:17 +0000 (01:48 +0000)
Original commit message from CVS:
added function gst_xml_write_file() which writes a nicely formatted and indented
xml representation of an element to a file. you can use stdout or stderr, for
example.

gst/gstxml.c
gst/gstxml.h

index 2bd8e07..121ecf8 100644 (file)
@@ -126,6 +126,64 @@ gst_xml_write (GstElement *element)
 }
 
 /**
+ * gst_xml_write_file:
+ * @element: The element to write out
+ * @out: an open file, like stdout
+ *
+ * Converts the given element into XML and writes the formatted XML to an open
+ * file.
+ *
+ * Returns: number of bytes written on success, -1 otherwise.
+ */
+gint
+gst_xml_write_file (GstElement *element, FILE *out)
+{
+  xmlDocPtr cur;
+  xmlOutputBufferPtr buf;
+  const char * encoding;
+  xmlCharEncodingHandlerPtr handler = NULL;
+  int indent;
+  gboolean ret;
+  
+  cur = gst_xml_write (element);
+  if (!cur) return -1;
+  
+#ifdef HAVE_LIBXML2
+  encoding = (const char *) cur->encoding;
+  
+  if (encoding != NULL) {
+    xmlCharEncoding enc;
+    
+    enc = xmlParseCharEncoding (encoding);
+    
+    if (cur->charset != XML_CHAR_ENCODING_UTF8) {
+      xmlGenericError (xmlGenericErrorContext,
+                       "xmlDocDump: document not in UTF8\n");
+      return -1;
+    }
+    if (enc != XML_CHAR_ENCODING_UTF8) {
+      handler = xmlFindCharEncodingHandler (encoding);
+      if (handler == NULL) {
+        xmlFree ((char *) cur->encoding);
+        cur->encoding = NULL;
+      }
+    }
+  }
+  
+  buf = xmlOutputBufferCreateFile (out, handler);
+  
+  indent = xmlIndentTreeOutput;
+  xmlIndentTreeOutput = 1;
+  ret = xmlSaveFormatFileTo(buf, cur, NULL, 1);
+  xmlIndentTreeOutput = indent;
+#else
+  ret = xmlDocDump (out, cur);
+#endif
+  
+  return ret;
+}
+
+/**
  * gst_xml_parse_doc:
  * @xml: a pointer to a GstXML object
  * @doc: a pointer to an xml document to parse
index da0566e..6c5d156 100644 (file)
@@ -69,6 +69,9 @@ GType         gst_xml_get_type        (void);
 /* create an XML document out of a pipeline */
 xmlDocPtr      gst_xml_write           (GstElement *element);
 
+/* write a formatted representation of a pipeline to an open file */
+gint           gst_xml_write_file      (GstElement *element, FILE *out);
+
 GstXML*                gst_xml_new             (void);
 
 gboolean       gst_xml_parse_doc       (GstXML *xml, xmlDocPtr doc, const guchar *root);