added function gst_xml_write_file() which writes a nicely formatted and indented xml representation of an element to ...

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.
This commit is contained in:
Andy Wingo 2002-01-11 01:48:17 +00:00
parent fe516689cc
commit 099074586c
2 changed files with 61 additions and 0 deletions

View file

@ -125,6 +125,64 @@ gst_xml_write (GstElement *element)
return doc;
}
/**
* 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

View 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);