tests: convert pretty_xml.c to C++
[lttng-tools.git] / tests / utils / xml-utils / pretty_xml.cpp
diff --git a/tests/utils/xml-utils/pretty_xml.cpp b/tests/utils/xml-utils/pretty_xml.cpp
new file mode 100644 (file)
index 0000000..3f296f0
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2021 EfficiOS Inc.
+ *
+ * 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(void)
+{
+       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.023808 seconds and 4 git commands to generate.