Skip to main content
Participating Frequently
June 27, 2011
Answered

< XML and TextFlowUtil.importFromXML

  • June 27, 2011
  • 1 reply
  • 1574 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 28, 2011

I got an error when running your code with debugger version of player.

TypeError: Error #1090: XML parser failure: element is malformed.

    at XMLTest/_XMLTest_XML1_i()
    at XMLTest()
    at _XMLTest_mx_managers_SystemManager/create()[_XMLTest_mx_managers_SystemManager.as:52]
    at mx.managers.systemClasses::ChildManager/initializeTopLevelWindow()
    at mx.managers::SystemManager/initializeTopLevelWindow()
    at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::kickOff()
    at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::preloader_completeHandler()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.preloaders::Preloader/timerHandler()
    at flash.utils::Timer/_timerDispatch()
    at flash.utils::Timer/tick()

I think it is because of the addtional "<". For more questions about <fx:XML>, pls post it to Flex forum.