As 3 read the XML implementation code

Source: Internet
Author: User
Tags addchild

As 3 read the XML implementation code

AS3 is really easy to do with XML (e4x ECMAScript for XML right. ECMAScript if JS is better than the classmate to this also very familiar with it).

Package
{
Import flash.display.*;
Import flash.text.*;
Import flash.xml.*;
Import flash.net.*;
Import flash.events.event;

public class Classsubfeed extends Sprite
{
var Temp:textfield;
var myxmlurl:urlrequest;
var Myloader:urlloader;
var xmlurl:string;
var xmlcontent:xml;

Public Function Classsubfeed ()
{
temp = new TextField ();
temp.x = 10;
TEMP.Y = 10;
Temp.width = 530;
Temp.height = 350;
Temp.border = true;
Temp.bordercolor = 0x669900;
Temp.multiline = true;
Temp.htmltext = ' loading ... ';
Addchild (temp);

XML address
XmlUrl = "Http://www.111cn.net/xml/5230.xml";
This.loadxml (XmlUrl);
}

Private Function Loadxml (xmlurl:string): void
{
Myxmlurl = new URLRequest (xmlurl);
Myloader = new Urlloader (Myxmlurl);
Myloader.addeventlistener (Event.complete, onloaded);
}

Private Function OnLoaded (event): void
{
Xmlcontent = XML (Myloader.data);
Temp.htmltext = ' already read feed, preparing ... '
This.parsedata (xmlcontent);
}

Private Function Parsedata (xmlcontent:xml): void
{
var rrstitle:string = Xmlcontent.channel.title;
var rrslink:string = Xmlcontent.channel.link;
Temp.htmltext = "
For each (Var item:xml in xmlcontent ...). Item
{
var itemtitle:string = item.title.tostring ();
var itemlink:string = item.link.tostring ();
Temp.htmltext + + <div>}
}
}
}

Instance two, reading an external XML file

<?xml version= "1.0" encoding= "Utf-8"?>
<mdragon table= "xxxxx" question1= "xxxxxx" question2= "xxxxxxxxxxxxxxx" time= "1" background= "2" >

 <question answer= "a" value= "period, when speaking with people)" "
            <answers value= "A: Wearing a mask"/>
           <answers Value= "B: Keep a distance"/>
           <answers value= "C: as usual "/>
           <answers value=" D: Less say a few words "/>
  </question>
 
</mdragon>
------------------------------ Readxml.as-------------------------------------------

Package
{
Import flash.events.event;
Import Flash.net.urlloader;
Import Flash.net.urlrequest;
Import flash.xml.xmldocument;
Import Flash.text.textfield;
Import Flash.text.textformat;
Import flash.text.textfieldautosize;
Import Flash.display.displayobjectcontainer;
Import Flash.display.sprite

public class ReadXml extends Sprite
{
private Var Myxml:xml;
private Var Myloader:urlloader;
private Var string:string;
private var mystr:string=new string ();
private Var myxmlurl:urlrequest;
private var txt:textfield=new textfield ();
private var Format:textformat = new TextFormat ();

Public Function ReadXml (myxmlurl:string): void
{
Myxmlurl=new urlrequest (Myxmlurl);
Myloader=new Urlloader ();
Myloader.addeventlistener (event.complete,xmlloaded);
Myloader.load (Myxmlurl);


}

Public Function xmlloaded (evt:event): void
{
Myxml=new XML (Evt.currenttarget.data);
Mystr=this.myxml.question[0]. @value;

TXT.TEXT=MYSTR;

Txt.autosize = Textfieldautosize.left;
Txt.background = true;
Txt.border = true;

Format.font = "Song Body";
Format.color = 0x000000;
Format.size = 15;
Format.underline = false;

Txt.defaulttextformat=format;

txt.x=50;
txt.y=200;

Trace (myXML);
Trace (MYSTR);

}

Public Function Returntext (target:displayobjectcontainer): void
{

Target.addchild (TXT);

}

}//end of Class
}//end of package

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.