Az Expattech az ünnepek alatt (dec.24-jan.1.) zárva tart. Nyitás: 2024.január 2

ExpatTech Techblog

Peter Todd 2010.09.30. 14:15

Flash Cookbook - Appendix - Practical XML - Something to know

Today I used the flash in-built xml capability for designing an xml:

var xml:XML = <data><obj>0</obj><obj>1</obj></data>;
trace(xml["obj"][1]); //outputs 1

when I arrived to a point, where I commented an item out:

var xml:XML = <data><obj>0</obj>/*<obj>1</obj>*/</data>;
trace(xml["obj"][1]); //outputs 1

Hm, I thought, what happened here (okay, for five minutes I didn't know what to do), I thought the flash miracoulusly cached my xml and loaded it from somewhere but not the IDE. Then came the hit: even though you think you've commented the part out, it didn't delete it from the xml. Of course if you want to comment this out, you need the standard notation.

var xml:XML = <data><obj>0</obj><!--<obj>1</obj>--></data>;
trace(xml["obj"][1]); //outputs undefined

But then what happens if you use the IDE's comment notations?

var xml:XML = <data><obj>0</obj>/*<obj>1</obj>*/</data>;
trace(xml);

Surprisingly outputs:

<data>
  <obj>0</obj>
  /*
  <obj>1</obj>
  */
</data>

and

var xml:XML = <data><obj>0</obj><!--<obj>1</obj>--></data>;
trace(xml);

outputs:

<data>
  <obj>0</obj>
</data>

Yes, xml takes whatever /**/ as a piece of the content. It doesn't matter, that you are working with flash in a flash IDE, it won't be a comment in your code if you use the XML type and its advantages (though we don't know the advantages of this initialization). Use the rules of XML in an XML type.