Add pretty_xml utils
[lttng-tools.git] / tests / utils / xml-utils / pretty_xml.c
diff --git a/tests/utils/xml-utils/pretty_xml.c b/tests/utils/xml-utils/pretty_xml.c
new file mode 100644 (file)
index 0000000..ccc1b23
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2021 Jonathan Rajotte <jonathan.r.julien@gmail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-only
+ *
+ */
+
+/*
+ * Prettyfi a xml input from stdin to stddout.
+ * This allows a more human friendly format for xml testing when problems occur.
+ */
+
+#include <libxml/parser.h>
+
+int main(int argc, char **argv)
+{
+       xmlDocPtr doc = NULL;
+
+       /* Init libxml. */
+       xmlInitParser();
+       xmlKeepBlanksDefault(0);
+
+       /* Parse the XML document from stdin. */
+       doc = xmlParseFile("-");
+       if (!doc) {
+               fprintf(stderr, "ERR parsing: xml input invalid");
+               return -1;
+       }
+
+       xmlDocFormatDump(stdout, doc, 1);
+
+       xmlFreeDoc(doc);
+       /* Shutdown libxml. */
+       xmlCleanupParser();
+
+       return 0;
+}
This page took 0.023173 seconds and 4 git commands to generate.