XMLHighlighter class

Availability

Flash Player 6 (copy the XMLHighlighter class actionscript file to the same folder as the FLA or to the class path).

Description

Use the methods and properties of the XMLHighlighter class to generate the html code to generate color highlighted pretty printed XML

Method summary for the XMLHighlighter class

Method Description
XMLHighlighter.highlight() Returns the HTML highlighted code for the specified XML document.

Property summary for the XMLHighlighter class

Property Description
XMLHighlighter.useCDATA Set to true by default. enables/disables the CDATA detection

XMLHighlighter class

Availability

Flash Player 6 (copy the XMLHighlighter class actionscript file to the same folder as the FLA).

Usage

var htmlTxt:String = XMLHighlighter.highlight(source:XML):String;

Parameters

source An XML parsed to generate the HTML String.

Returns

Color highlighted HTML String.

Description

Since it is a static class, call any of the methods of the XMLHighlighter class directly.

Note: Set XMLHighlighter.useCDATA=false if you don’t want to use CDATA for text nodes.

Example

The following example creates a new, empty XML object:

 

[cc lang=”actionscript3″]

var s = '<?xml version="1.0"?><!DOCTYPE greeting SYSTEM "hello.dtd"><note>r';
s += '    This is mytext node  r    ';
s += '<![CDATA[ This is my <b>CDATA</b>Section node ]]>r<note attribute="value"/></note>';
var x:XML = new XML(s);
//by default it will enable CDATA if you dont want that to happen
//uncomment the following line
//XMLHighlighter.useCDATA=false;
var s2 = XMLHighlighter.highlight(x);
//keep a copy of textArea component on stage and name it "textAreaInstance"
textAreaInstance.html = true;
textAreaInstance.text = s2;
trace(s2);

[/cc]


 

Resulting HTML

<?xml version="1.0"?>
<!DOCTYPE greeting SYSTEM "hello.dtd">
<note>
    This is mytext node
    <![CDATA[ This is my <b>CDATA</b>Section node ]]>
	<note attribute="value"/>
</note>