Debian Codegraph @

src/common/pretty-print.c

raw
1 /*
2 * Copyright (C) 2011 Jens Georg <[email protected]>
3 *
4 * Authors: Jens Georg <[email protected]>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21 #include <config.h>
22
23 #include "pretty-print.h"
24
25 #include <libxml/globals.h>
26 #include <libxml/xmlreader.h>
27
28 #include <string.h>
29
30 char *
31 pretty_print_xml (const char *xml)
32 {
33 xmlDocPtr doc;
34 char *text;
35 int length;
36
37 doc = xmlReadMemory (xml,
38 strlen (xml),
39 NULL,
40 NULL,
41 XML_PARSE_NONET | XML_PARSE_RECOVER);
42
43 if (!doc)
44 return NULL;
45
46 xmlDocDumpFormatMemoryEnc (doc,
47 (xmlChar **) &text,
48 &length,
49 "UTF-8",
50 1);
51 xmlFreeDoc (doc);
52
53 return text;
54 }