I am trying to generate an Excel-compatible XML file from Mathematica. First, I created a test XML file by saving a Microsoft Excel workbook as "XML Table". Then I Import
ed this file:
XMLdata = Import["test.xml", "IncludeNamespaces" -> True]
Now I am Export
ing this back to XML:
Export["test_exported.xml", XMLdata, "AttributeQuoting" -> "\""]
The generated file cannot be opened by Excel. Comparing it with the original file shows that most of namespace prefixes are dropped although they were present in XMLdata
. Why does this happen? How can I correctly Export
an XML file which will be compatible with Excel?
Answer
I have found the solution. From the Documentation,
Some documents use names in a non-namespace-compliant fashion, because the XML namespace recommendation, which extends XML, was made after the initial XML recommendation.
"IncludeNamespaces"->"Unparsed"
is provided to allow parsing of these documents. The name is always represented as the exact single string that appears in the XML file. Unless absolutely necessary, this option value should not be used.
With the option "IncludeNamespaces"->"Unparsed"
everything is nice and even the "AttributeQuoting" -> "\""
option is not needed:
XMLData = Import["test.xml", "IncludeNamespaces" -> "Unparsed"];
Export["test-from MMa.xml", XMLData]
The exported file is opened by Excel without warnings.
Comments
Post a Comment