[gst-devel] formatted xml convenience routine
Andy Wingo
wingo at pobox.com
Wed Jan 9 22:26:02 CET 2002
this is a temporary convenience workaround for libxml2's insistence on
not indenting. ok to commit?
Index: gstxml.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/gstxml.c,v
retrieving revision 1.24
diff -u -r1.24 gstxml.c
--- gstxml.c 2001/12/14 22:59:21 1.24
+++ gstxml.c 2002/01/10 06:23:18
@@ -126,6 +126,54 @@
}
/**
+ * gst_xml_write:
+ * @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: TRUE on success, FALSE otherwise.
+ */
+gboolean
+gst_xml_dump (GstElement *element, FILE *out)
+{
+ xmlDocPtr cur;
+ xmlOutputBufferPtr buf;
+ const char * encoding;
+ xmlCharEncodingHandlerPtr handler = NULL;
+ int ret;
+
+ cur = gst_xml_write (element);
+ if (!cur) return FALSE;
+
+ 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 FALSE;
+ }
+ if (enc != XML_CHAR_ENCODING_UTF8) {
+ handler = xmlFindCharEncodingHandler (encoding);
+ if (handler == NULL) {
+ xmlFree ((char *) cur->encoding);
+ cur->encoding = NULL;
+ }
+ }
+ }
+
+ buf = xmlOutputBufferCreateFile (out, handler);
+
+ return (xmlSaveFormatFileTo(buf, cur, NULL, 1) == 0);
+}
+
+/**
* gst_xml_parse_doc:
* @xml: a pointer to a GstXML object
* @doc: a pointer to an xml document to parse
Index: gstxml.h
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/gstxml.h,v
retrieving revision 1.17
diff -u -r1.17 gstxml.h
--- gstxml.h 2001/12/15 18:15:13 1.17
+++ gstxml.h 2002/01/10 06:23:18
@@ -69,6 +69,9 @@
/* create an XML document out of a pipeline */
xmlDocPtr gst_xml_write (GstElement *element);
+/* dump a formatted representation of a pipeline to an open file */
+gboolean gst_xml_dump (GstElement *element, FILE *out);
+
GstXML* gst_xml_new (void);
gboolean gst_xml_parse_doc (GstXML *xml, xmlDocPtr doc, const guchar *root);
More information about the gstreamer-devel
mailing list