Skip to main content
Participating Frequently
June 27, 2011
Answered

< XML and TextFlowUtil.importFromXML

  • June 27, 2011
  • 1 reply
  • 1566 views

Hi,

I am using flex. But it is about an XML importation so maybe it is the right place to post it (I previously tried on the Flex forum without success).

I want to display some Xml Files. Here I reproduce my code:

* my main file

<?xml version="1.0" encoding="utf-8" ?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               > 

   <fx:Script>
    <![CDATA[
         import spark.utils.TextFlowUtil;
         XML.ignoreWhitespace = false;        
    ]]>
   </fx:Script>
   <fx:Declarations>
     <fx:XML id="xmlFile" source="testxml.xml"/>
   </fx:Declarations>
   <s:Panel>
     <s:RichEditableText id="code2" editable="false"
            textFlow="{TextFlowUtil.importFromXML(xmlFile)}"/>
   </s:Panel>
  
</s:Application>

* testxml.xml

<?xml version="1.0" encoding="utf-8"?>
<TextFlow xmlns="http://ns.adobe.com/textLayout/2008
      whiteSpaceCollapse="preserve">
<span>Coucou</span> &lt;
</TextFlow>

If  testxml.xml does not contain &lt; (or &rt;), this works fine,  but as soon as I put this caracters, whereas the compilation works, the  application does not appear in my brownser (I use Linux,  I don't have  any error message).

Thanks for your help.

This topic has been closed for replies.
Correct answer Jin-Huang

Sorry, but I am continuing with my code . And something really strange is that the code above works fine withe the caracter &gt; !!

How is it possible ?? I really do not understand what happens!

BTW in what way your code can help me? (before I try to understard it)

Thanks


You only need to change the name of the xml file, then with my code, your markup will be imported as textflow even with "&lt;" in the markup.

<?xml version="1.0" encoding="utf-8" ?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx" addedToStage="importer()">
   
   
   
    <fx:Script>
        <![CDATA[
           
           
            import flash.events.*;
            import flash.net.URLLoader;
            import flash.net.URLRequest;
           
            import flashx.textLayout.conversion.*;
            import flashx.textLayout.elements.*;
            import flashx.textLayout.formats.TextLayoutFormat;
           
            var urlRequest:URLRequest;
           
            var urlLoader:URLLoader;
           
           
           
            public function importer()
               
            {
               
                urlRequest = new URLRequest('x.xml');
               
                urlLoader = new URLLoader();
               
                urlLoader.addEventListener(Event.COMPLETE, caricato);
               
                urlLoader.addEventListener(IOErrorEvent.IO_ERROR, erroreCaric);
               
                urlLoader.load(urlRequest);
               
            }
           
            function erroreCaric(e:IOErrorEvent):void
               
            { trace("error: file not found"); }
           
            function caricato(e:Event):void
               
            {
               
               var markup:XML = new XML(e.target.data);
               
                var config:Configuration = new Configuration();
               
                var format:TextLayoutFormat = new TextLayoutFormat(config.textFlowInitialFormat);
               
                format.whiteSpaceCollapse = "collapse";
               
                config.textFlowInitialFormat = format;
               
                var imp:ITextImporter = TextConverter.getImporter(TextConverter.TEXT_LAYOUT_FORMAT, config);
               
                imp.throwOnError = false;
               
                code2.textFlow = imp.importToFlow(markup);

               
            }
        ]]>
    </fx:Script>
   
        <s:RichEditableText id="code2"/>
   
   
</s:Application>

1 reply

Adobe Employee
June 28, 2011

You can have a look at #5 in http://forums.adobe.com/thread/868126?tstart=0, it works with your XML which has "&lt;" in it.

If it does not work in your side, you may need to download a new Flex SDK. I'm using Flex SDK 4.5

Participating Frequently
June 28, 2011

Thank you but I am using:

notezik@euclide:~ $ mxmlc -help
Adobe Flex Compiler (mxmlc)
Version 4.5.0 build 20967

You are asking me to try with the complex code of #5, but did you try with the little example I have provided?

What is wrong with my code?

Thank you very much to help me!

Adobe Employee
June 30, 2011

Yes it is working but it does not explain why my code does not.

But thank you very much.


Only Flex guys can explain the problem you met.