File: pretty_xml.cpp

package info (click to toggle)
ltt-control 2.14.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,400 kB
  • sloc: cpp: 192,720; sh: 29,271; ansic: 10,960; python: 7,419; makefile: 3,534; java: 109; xml: 46
file content (39 lines) | stat: -rw-r--r-- 818 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
 * SPDX-FileCopyrightText: 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 "common.hpp"

#include <common/scope-exit.hpp>

#include <iostream>
#include <libxml/parser.h>
#include <unistd.h>

namespace ll = lttng::libxml;

int main()
{
	const ll::global_parser_context global_parser_context;
	const ll::parser_ctx_uptr parserCtx{ xmlNewParserCtxt() };

	/* Parse the XML document from stdin. */
	const ll::doc_uptr doc{ xmlCtxtReadFd(
		parserCtx.get(), STDIN_FILENO, nullptr, nullptr, XML_PARSE_NOBLANKS) };
	if (!doc) {
		std::cerr << "Error: invalid XML input on stdin\n";
		return -1;
	}

	xmlDocFormatDump(stdout, doc.get(), 1);

	return 0;
}