# Whitespace is lost during MathML -> XMLElement conversion

ImportString["<mtext> </mtext>", {"MathML", "XMLElement"} ]

XMLElement["mtext",{},{}]


while I'd expect:

XMLElement["mtext",{},{" "}]


It's more than inconvenient because:

ExportString[
XMLElement["mtext", {}, {}],
"XML"
]

"<mtext />"


when I need:

ExportString[
XMLElement["mtext", {}, {" "}],
"XML"
]

"<mtext> </mtext>"


Is this expected?

• Have you tried ExportString[ImportString["<mtext> </mtext>", {"MathML", "XMLElement"}, "NormalizeWhitespace" -> False], "XML"]. "NormalizeWhitespace" set to false instead of the default Automatic. The less instructions given at Import or Export the more one gives control to WRI logic for Automatic expectations. Automagic. – Hans Oct 20 '15 at 14:13
• @Hans nice, wasn't aware of that. Please consider posting an answer :) – Kuba Oct 20 '15 at 14:19

## 1 Answer

Try

ExportString[ImportString["<mtext> </mtext>", {"MathML", "XMLElement"}, "NormalizeWhitespace" -> False], "XML"]


From XML/tutorial/ImportingXML. I thought the default for "NormalizeWhitespace" was Automatic. However the documentation states that "True" is the default, where "all the whitespace inside an element is normalized (default)".

• I wouldn't say expected due to the fact that ImportString ref page contains no info about available options. – Kuba Oct 20 '15 at 14:31
• The ref/ImportString page contains a pointer to Import under Details. It would be nicer if WRI just simply reiterated the options under ImportString. – Hans Oct 20 '15 at 14:40
• and where is this option mentioned on Import page? ;) – Kuba Oct 20 '15 at 14:46
• It is not. One would have to dig 4 levels into the Tutorial to get this information for "XML" format XML/tutorial/ImportingXML. I just meant the pointer note in the Details of ImportString "ImportString works just like Import, with the same element specifications and options." However, the way I got to this information was to type "NormalizeW*" in the Help. Just using prior knowledge of normalizing white space in SGML, XML, HTML with recollection that Mathematica has a "NormalizeWhitespace" option. I actually knew how to use it. But still searched for spelling. – Hans Oct 20 '15 at 15:04