Skip to main content
Known Participant
January 29, 2011
Question

Export xml and importing it back in

  • January 29, 2011
  • 1 reply
  • 1517 views

I've got an issue I can't seem to find an answer to on the forums or otherwise.

I'm creating a screenwriting app in AIR that saves a file to the user's local machine.

If I place this line of code for the import on the constructor it works fine and sets up the document for writing.

private const textMarkup:String = "<TextFlow xmlns='http://ns.adobe.com/textLayout/2008' verticalScrollPolicy='auto' horizontalScrollPolicy='auto' fontSize='12' fontFamily='Courier New' paddingTop='60' paddingLeft='120' paddingRight='55' typographicCase='uppercase' xmlns='http://ns.adobe.com/textLayout/2008'></TextFlow>";

Now, I have an export function that exports this data out as an XML

public function exportScript():void {

     var exportXML:XML = TextConverter.export(textFlow, TextConverter.TEXT_LAYOUT_FORMAT, ConversionType.XML_TYPE) as XML;

     var myScript:String = "myScript";

     exportFile.save(exportXML, myScript + '.FadeIn');

}

This function works perfectly.  However, when it saves the XML file the formatting is altered.  I get this.

<TextFlow fontFamily="Courier New" fontSize="12" horizontalScrollPolicy="auto" paddingLeft="120" paddingRight="55" paddingTop="60" typographicCase="uppercase" verticalScrollPolicy="auto" whiteSpaceCollapse="preserve" version="2.0.0" xmlns="http://ns.adobe.com/textLayout/2008">

  <p>

    <span></span>

  </p>

</TextFlow>

Because of the " replacing '  and the // it tosses the whole thing out of whack and won't import correctly. 

This topic has been closed for replies.

1 reply

Adobe Employee
January 31, 2011

The XML is normalized on export. This means that you're getting an empty paragraph added, as well as a version attribute and whitespaceCollapse attribute. That's equivalent to what you imported, so it should be OK. What looks like it might cause a problem is the extra whitespace in the XML on the export. Somewhere along the way the XML was pretty-printed, adding tabs and returns, which would be fine if the XML were just standard database records, but in this case its text, and text can legally contain tabs and returns. The first thing I would try is doing the export into a String using ConversionType.STRING_TYPE. Then TLF will take care of the conversion from XML to string for you, and you will not get any pretty printing from that part of the operation.

- robin

ddfletchAuthor
Known Participant
January 31, 2011

So here are my three functions.  1 exports the text.  2 imports the script and 3 fires upon completion of 2.  I'm exporting in a string and using the text_layout_format to bring it back in but I get nothing on the screen when this third function fires.   What am I doing wrong?

public function exportScript():void {

var exportXML:String = TextConverter.export(textFlow, TextConverter.TEXT_LAYOUT_FORMAT, ConversionType.STRING_TYPE) as String;

var myScript:String = "myScript";

exportFile.save(exportXML, myScript + '.FadeIn');

}

public function importScript():void {

xmlLoader.addEventListener(Event.COMPLETE, importComplete);

xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, importError);

xmlLoader.load(new URLRequest("myScript.FadeIn"));

}

public function importComplete(e:Event):void {

xmlContent = new XML(xmlLoader.data);

textFlow = TextConverter.importToFlow(xmlContent, TextConverter.TEXT_LAYOUT_FORMAT);

xmlLoader.removeEventListener(Event.COMPLETE, importComplete);

xmlLoader.removeEventListener(IOErrorEvent.IO_ERROR, importError);

}

ddfletchAuthor
Known Participant
January 31, 2011

By importing the xmlLoader.data into a string, I can trace out the xmlContent and it has no spaces or returns in it.  But I can't get the importToFlow line to do anything.