Files
PowerToys/tools/BugReportTool/BugReportTool/XmlDocumentEx.cpp
Jiří Polášek bc8adb3189 BugReport: Fix incorrect XML closing tag syntax generated by XmlDocumentEx (#42399)
## Summary of the Pull Request

The `XmlDocumentEx::Print` method previously used `<\\` to close XML
tags, which is invalid. This commit replaces `<\\` with `</` to ensure
proper XML closing tag syntax.

Changes include:
- Replacing `<\\` with `</` in three instances where closing tags are
generated.
- Ensuring the XML output conforms to standard XML syntax.

These changes improve the correctness of the XML output generated by the
method.

<img width="1014" height="499" alt="image"
src="https://github.com/user-attachments/assets/a9ff6e47-6976-4290-a4f0-c23b0c773d61"
/>


<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [x] Closes: #42390
- [x] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [x] **Tests:** Added/updated and all pass
- [x] **Localization:** All end-user-facing strings can be localized
- [x] **Dev docs:** Added/updated
- [x] **New binaries:** Added on the required places
- [x] **Documentation updated:** 

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
2025-10-20 12:00:04 -05:00

57 lines
1.4 KiB
C++

#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">";
}