Fx{r} is trying to start the Fx{r} Community! Please join our group on Adobe Groups following this link: http://groups.adobe.com/groups/ab29539ab9.
Fx{r} is now on Twitter too. Follow us @ twitter.com/fx_r!
«
»

ActionScript, Bugs

toString() vs xmlToString()

Andrei Ionescu | 29.01.08 | Comment?

Google Buzz

I don’t know if you got in trouble when working with xmls but recently I found a bug (or a feature). Some differences when using toString() and/or xmlToString().

Take a look a the following code:

public var test1:XML = new XML("
<permissions></permissions>
");
public var test2:XML =
<permissions></permissions>;
 
public var test3:XML = new XML("
<permissions>
    <test1>test</test1>
</permissions>");
public var test4:XML =
<permissions>
    <test1>test</test1>
</permissions>;
 
public var test5:XML = new XML("
<permissions>test</permissions>
");
public var test6:XML =
<permissions>test</permissions>;
 
public function init():void
{
    debugWin.text = "";
 
    var respTest1:String = test1.toString();
    var respTest2:String = test2.toString();
 
    var respTest3:String = test1.toXMLString();
    var respTest4:String = test2.toXMLString();
 
    var respTest5:String = test3.toString();
    var respTest6:String = test4.toString();
 
    var respTest7:String = test3.toXMLString();
    var respTest8:String = test4.toXMLString();
 
    var respTest9:String = test5.toString();
    var respTest10:String = test6.toString();
 
    var respTest11:String = test5.toXMLString();
    var respTest12:String = test6.toXMLString();
 
    debugWin.text += "\n";
    debugWin.text += "["+respTest1+"]";
    debugWin.text += "\n";
    debugWin.text += "["+respTest2+"]";
    debugWin.text += "\n";
    debugWin.text += "\n";
    debugWin.text += "["+respTest3+"]";
    debugWin.text += "\n";
    debugWin.text += "["+respTest4+"]";
    debugWin.text += "\n";
    debugWin.text += "\n";
    debugWin.text += "["+respTest5+"]";
    debugWin.text += "\n";
    debugWin.text += "["+respTest6+"]";
    debugWin.text += "\n";
    debugWin.text += "\n";
    debugWin.text += "["+respTest7+"]";
    debugWin.text += "\n";
    debugWin.text += "["+respTest8+"]";
    debugWin.text += "\n";
    debugWin.text += "\n";
    debugWin.text += "["+respTest9+"]";
    debugWin.text += "\n";
    debugWin.text += "["+respTest10+"]";
    debugWin.text += "\n";
    debugWin.text += "\n";
    debugWin.text += "["+respTest11+"]";
    debugWin.text += "\n";
    debugWin.text += "["+respTest12+"]";
}

The text inside the debugWin (this is a TextArea) is the following (the square brackets to see what’s the content of the strings):

[]
[]
 
[
<permissions></permissions>]
[
<permissions></permissions>]
 
[
<permissions>
  <test1>test</test1>
</permissions>]
[
<permissions>
  <test1>test</test1>
</permissions>]
 
[
<permissions>
  <test1>test</test1>
</permissions>]
[
<permissions>
  <test1>test</test1>
</permissions>]
 
[test]
[test]
 
[
<permissions>test</permissions>]
[
<permissions>test</permissions>]

As you can see whe using toString() on an empty node the return is null but when using xmlToString() on the same empty node the return is the containing empty node. The same happen also when using content but not child nodes, but is different if the node has child nodes in it. So I don’t know if this is a bug or a feature or this is the way it should behave.

If you have experience with XML please share it with us.

Share and Enjoy:
  • Twitter
  • Google Buzz
  • LinkedIn
  • Google Bookmarks
  • del.icio.us
  • Digg
  • Sphinn
  • blogmarks
  • Reddit
  • StumbleUpon
  • Facebook
  • DZone
  • FriendFeed
  • Yahoo! Buzz
  • Yahoo! Bookmarks
  • Slashdot
  • MySpace
  • Add to favorites




Tags: , , ,

This post was written by Andrei Ionescu

Views: 3067

related

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

:

:


«
»