fix raw-xml formatting (remove XML declaration) v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Tue, 23 Nov 2021 20:37:35 +0100
branchv_0
changeset 30 6507d454b9a6
parent 29 cc601886f0a7
child 31 939e597f5738
fix raw-xml formatting (remove XML declaration)
src/XMLTableCommand.h
--- a/src/XMLTableCommand.h	Tue Jun 08 22:53:20 2021 +0200
+++ b/src/XMLTableCommand.h	Tue Nov 23 20:37:35 2021 +0100
@@ -43,7 +43,10 @@
 	std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings.
 
 	string_t formatRawXML(string_t rawXML) {
-		std::wregex pattern(L"^<\\?xml version=\"1.0\" encoding=\"UTF-8\"\\?>\n|\n$");
+		std::wregex pattern(L"^(<\\?xml version=\"1.0\" encoding=\"UTF-8\"\\?>\\s*)+|\n$");
+		// libxml sometimes returns doubled XML declaration (probably a bug), see:
+		// --relation ini --records '/' --attribute 'xml' string '.' --mode raw-xml # (but not for --records '//*')
+		// so we remove all of them and also trailing line ends (if any).
 		return std::regex_replace(rawXML, pattern, L"");
 	}