Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

XML Viewer in Flash

Participant ,
Feb 27, 2014 Feb 27, 2014

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.

TOPICS
ActionScript
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 02, 2014 Mar 02, 2014

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

...
Translate
Mentor ,
Feb 28, 2014 Feb 28, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 28, 2014 Feb 28, 2014

Thanks for the information.

But, My objective is to make the user view the xml some thing like below.

xml.png

Any reference or idea will be really helpful.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Feb 28, 2014 Feb 28, 2014
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 02, 2014 Mar 02, 2014

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>;

                    }

          }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 02, 2014 Mar 02, 2014
LATEST

Thanks for the sample and for the time you spent for this. It will be really helpful for me to acheive.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines