mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 10:16:24 +02:00
[Bug Report Tool] Report event viewer logs (#11458)
This commit is contained in:
56
tools/BugReportTool/BugReportTool/XmlDocumentEx.cpp
Normal file
56
tools/BugReportTool/BugReportTool/XmlDocumentEx.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "XmlDocumentEx.h"
|
||||
|
||||
#include <winrt/Windows.Foundation.Collections.h>
|
||||
|
||||
std::wstring XmlDocumentEx::GetFormatedXml()
|
||||
{
|
||||
stream.clear();
|
||||
Print(FirstChild(), 0);
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
void XmlDocumentEx::Print(winrt::Windows::Data::Xml::Dom::IXmlNode node, int indentation)
|
||||
{
|
||||
for (int i = 0; i < indentation; i++)
|
||||
{
|
||||
stream << " ";
|
||||
}
|
||||
|
||||
PrintTagWithAttributes(node);
|
||||
if (!node.HasChildNodes())
|
||||
{
|
||||
stream << L"<\\" << node.NodeName().c_str() << ">" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (node.ChildNodes().Size() == 1 && !node.FirstChild().HasChildNodes())
|
||||
{
|
||||
stream << node.InnerText().c_str() << L"<\\" << node.NodeName().c_str() << ">" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
stream << std::endl;
|
||||
auto child = node.FirstChild();
|
||||
do
|
||||
{
|
||||
Print(child, indentation + 2);
|
||||
} while (child = child.NextSibling());
|
||||
|
||||
for (int i = 0; i < indentation; i++)
|
||||
{
|
||||
stream << " ";
|
||||
}
|
||||
stream << L"<\\" << node.NodeName().c_str() << ">" << std::endl;
|
||||
}
|
||||
|
||||
void XmlDocumentEx::PrintTagWithAttributes(winrt::Windows::Data::Xml::Dom::IXmlNode node)
|
||||
{
|
||||
stream << L"<" << node.NodeName().c_str();
|
||||
for (int i = 0; i < (int)node.Attributes().Size(); i++)
|
||||
{
|
||||
auto attr = node.Attributes().GetAt(i);
|
||||
stream << L" " << attr.NodeName().c_str() << L"='" << attr.InnerText().c_str() << L"'";
|
||||
}
|
||||
|
||||
stream << L">";
|
||||
}
|
||||
Reference in New Issue
Block a user