3 Replies Latest reply on Feb 3, 2011 1:29 AM by datafunk

    TextFlow XML export issue with missing whitespaces

    Dominic Thwaites

      If I export a TextFlow into XML (with either TextFlowUtil or TextConverter) it will lose white spaces where they occur between elements, so that a subsequence import will yield different content from the original. A simple example being:


      "Where is my white space". Will export and re-import to give: "Whereismywhitespace".


      This happens in the XML build process because when a text node is programatically appended (with appendChild()) white spaces are stripped from the start and end. For example, if you do xml.appendChild("     hello    ") you actually get an XML element containing just "hello".


      Now I understand there is a directive (XML.ignoreWhiteSpace) to ignore or keep white space when parsing nodes already set in the XML, but I cannot see how to do this when you are building the XML from some data structure (like a TextFlow), or indeed when creating an XML object from a String that contains XML notation.


      I am unaware how you can include surrounding whitespace in an XML node (short of CDATA). And the fact that the TextFlow XML import/export loses information seems to make it, well, pretty pointless.


      So, how do I retain these white spaces in a TextFlow in an exported XML?

        • 1. Re: TextFlow XML export issue with missing whitespaces

          You need to set XML.ignoreWhitespace = false; and use the white space collapse argument in the importFromXML method like this:


          summary.textFlow = TextFlowUtil.importFromXML(summaryXml, WhiteSpaceCollapse.PRESERVE);

          • 2. Re: TextFlow XML export issue with missing whitespaces
            Dominic Thwaites Level 1



            Many thanks for replying. Unfortunately, your suggestion bypasses the problem. The problem is I am starting from a STRING not XML. It's getting the String into an XML whilst preserving the whitespace that is the root of the problem.


            I am not simply exporting and re-importing to/from XML, I am exporting to XML, persisting this as a STRING, and then I need to re-import from that STRING. It's the creation of an XML object from a STRING that actually is the culprit, not really the Textflow export/import to XML.


            Perhaps you've got a nice simple solution for that one...?





            • 3. Re: TextFlow XML export issue with missing whitespaces

              The solution for this problem consists of two parts.


              First part is exporting the xml from the textflow, you want no formatted XML (with breaks, tabs, ...), but one long string with the spaces left like there were entered between the tags, this can be done with:


              _textXML = TextConverter.export(EditorID.textFlow,TextConverter.TEXT_LAYOUT_FORMAT,ConversionType.STRING_TYPE) as String;


              Use the TextConverter in stead of the TextFlowUtil.


              Second part is back importing to textFlow:

              There the solution mentioned above was correct.


              XML.ignoreWhitespace = false;
              var flowXML:XML = new XML(_textXML);
              contentTLF = TextFlowUtil.importFromXML(flowXML,WhiteSpaceCollapse.PRESERVE);

              1 person found this helpful