Ignoring comments in an XML file in ActionScript 3.0

by Peter deHaan on August 22, 2008

in ActionScript, XML

The following example shows how you can ignore comment tags (<!-- … -->) in an XML document by setting the static XML.ignoreComments property.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/08/22/ignoring-comments-in-an-xml-file-in-actionscript-30/ -->
<mx:Application name="XML_ignoreComments_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            XML.ignoreComments = false;

            private const xmlObj:XML = <TestCase>
                        <setup>
                            <!-- TODO: implement -->
                        </setup>
                        <body>
                            <!-- TODO: implement -->
                        </body>
                    </TestCase>;

            private function init():void {
                XML.ignoreComments = ignoreCommentsCheckBox.selected;

                var newXMLObj:XML = xmlObj.copy();
                textArea.text = newXMLObj.toXMLString();
            }
        ]]>
    </mx:Script>

    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="ignoreComments:">
                <mx:CheckBox id="ignoreCommentsCheckBox"
                        change="init();" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:TextArea id="textArea"
            editable="false"
            width="100%"
            height="100%"
            creationComplete="init();" />

</mx:Application>

View source is enabled in the following example.

{ 1 comment… read it below or add one }

1 Margaret August 12, 2009 at 7:23 am

Thank you Peter, couldn’t figure out why my xml comments were getting dropped until I came across this blog.

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

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

Anti-Spam Protection by WP-SpamFree

Previous post:

Next post: