Copy link to clipboard
Copied
HI,
Would like to know is it possible view xml online. I am looking something like XML browser view inside the application. I am using CS6 AS3.
If you are talking about displaying XML formatted certain way, the bad news is that there is no free code available that will accomplish everything you require.
The good news is that it is possible to write your own application and it is not all that difficult.
To colorize text the best way is to use Regular Expressions in conjunction withTextField.setTextFormat() method. The trick is to identify string patterns to cover all possible XML parts features.
The code below applies color to different par
...Copy link to clipboard
Copied
Its possible if you mean viewing an xml file that is located on a server or on alocal computer:
Basics can be found here:
http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ff5.html
you could even use sth. like
http://www.greensock.com/xmlparseras2/ (there is also a as3 version in the description)
to further reduce your time investment
Copy link to clipboard
Copied
Thanks for the information.
But, My objective is to make the user view the xml some thing like below.

Any reference or idea will be really helpful.
Copy link to clipboard
Copied
use this property to show an xml in its original state:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XML.html#toXMLString%28%29
Copy link to clipboard
Copied
If you are talking about displaying XML formatted certain way, the bad news is that there is no free code available that will accomplish everything you require.
The good news is that it is possible to write your own application and it is not all that difficult.
To colorize text the best way is to use Regular Expressions in conjunction withTextField.setTextFormat() method. The trick is to identify string patterns to cover all possible XML parts features.
The code below applies color to different parts of a sample XML - just make this class your document class if you use Flash IDE.
As far as collapse/expand goes - it is a more complex endeavor although it is within reach with a little effort and basic knowledge of AS3 display list model.
package
{
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
public class XMLViewer extends Sprite
{
private var xml:XML;
private var textField:TextField;
public function XMLViewer()
{
init();
}
private function init():void
{
writeXML();
displayXML();
}
/**
* Creates a TextField instance for displaying XML string
*/
private function displayXML():void
{
textField = new TextField();
textField.defaultTextFormat = new TextFormat("Arial", 12);
textField.multiline = true;
textField.autoSize = "left";
textField.text = xml.toXMLString();
addChild(textField);
formatText();
}
private function formatText():void
{
var xmlString:String = xml.toXMLString();
var format:TextFormat = new TextFormat("Arial", 12, 0x0000FF);
// format brackets
applyFormat(format, /[\<\>\=\/\"]/g);
// format tags
format.color = 0xA05050;
applyFormat(format, /\w+/g);
// format values
format.color = 0x000000;
format.bold = true;
applyFormat(format, /(?<=\")[\w\s]+(?=\")|(?<=\>)[\w\s]+(?=\<)/g);
// format CDATA
format.color = 0x0000FF;
format.bold = false;
applyFormat(format, /(\<\!\[CDATA\[)|(\]\])/g);
// format CDATA content
format.color = 0x000000;
format.bold = false;
applyFormat(format, /(?<=CDATA\[).+(?=\]\])/g);
}
/**
* Applies format to textField instance based on format and regular expression arguments
* @param format
* @param re
*/
private function applyFormat(format:TextFormat, re:RegExp):void
{
var string:String = textField.text;
var result:Object = re.exec(string);
while (result != null)
{
var index:int = result.index;
textField.setTextFormat(format, index, index + result[0].length);
result = re.exec(string);
}
}
/**
* Just composes sample XML
*/
private function writeXML():void
{
xml = <Resources>
<Book name="Book 1" ISDN="4898990" />
<Book name="Book 2" ISDN="34564576" />
<Novel name="Novel 1" ISDN="3569356">
<Description>Novel 1 description</Description>
</Novel>
<HTMLData><![CDATA[<a href="http://www.google.com>here we go</a> ]]></HTMLData>
</Resources>;
}
}
}
Copy link to clipboard
Copied
Thanks for the sample and for the time you spent for this. It will be really helpful for me to acheive.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more