4
$\begingroup$
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?

$\endgroup$
2
  • 1
    $\begingroup$ 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. $\endgroup$
    – Hans
    Oct 20, 2015 at 14:13
  • $\begingroup$ @Hans nice, wasn't aware of that. Please consider posting an answer :) $\endgroup$
    – Kuba
    Oct 20, 2015 at 14:19

1 Answer 1

4
$\begingroup$

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)".

$\endgroup$
4
  • $\begingroup$ I wouldn't say expected due to the fact that ImportString ref page contains no info about available options. $\endgroup$
    – Kuba
    Oct 20, 2015 at 14:31
  • $\begingroup$ The ref/ImportString page contains a pointer to Import under Details. It would be nicer if WRI just simply reiterated the options under ImportString. $\endgroup$
    – Hans
    Oct 20, 2015 at 14:40
  • $\begingroup$ and where is this option mentioned on Import page? ;) $\endgroup$
    – Kuba
    Oct 20, 2015 at 14:46
  • $\begingroup$ 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. $\endgroup$
    – Hans
    Oct 20, 2015 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.