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.
Popularity: 20%
Tags: ActionScript, bug, string, xml
This post was written by Andrei Ionescu
Views: 826


















