XML - Adobe ActionScript® 3(AS3 )API リファレンス
package {
import flash.display.Sprite;
import flash.text.*;
public class XmlExample extends Sprite {
var _tf:TextField;
//var _tfm:TextFormat;
public function XmlExample() {
_tf = new TextField();
_tf.autoSize = TextFieldAutoSize.LEFT;
addChild(_tf);
var employees:XML =
11 Main St.
San Francisco
CA
98765
99 Broad St.
Newton
MA
01234
;
//trace(employees.employee[0].address.zip); // 98765
_tf.appendText(employees.employee[0].address.zip+"\n");
//trace(employees.employee[1].@ssn); // 789-789-7890
_tf.appendText(employees.employee[1].@ssn+"\n"); // 789-789-7890
_tf.appendText(employees.employee.name+"\n"); //
//
_tf.appendText(employees..zip[0]+"\n"); // 98765
_tf.appendText(employees..@ssn[1]+"\n"); // 789-789-7890
_tf.appendText(employees..name+"\n"); //
//
_tf.appendText(employees.employee[0].address.*); // 11 Main St.
// San Francisco
// CA
// 98765
var node:String = "zip";
_tf.appendText(employees.employee[0].address[node]+"\n"); // 98765
var attribute:String = "ssn";
_tf.appendText(employees.employee[1].@[attribute]+"\n"); // 789-789-7890
for each (var num:XML in employees..@ssn) {
_tf.appendText(num+"\n"); // 123-123-1234
} // 789-789-7890
var ssnToFind:String = "789-789-7890";
_tf.appendText(employees.employee.(@ssn == ssnToFind).toXMLString());
//
//
//
// 99 Broad St.
// Newton
// MA
// 01234
//
//
}
}
}
Link
SyntaxHighlighter の最後の行がおかしな表示になるな
package;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.display.BitmapData;
import flash.display.Bitmap;
import openfl.Assets;
//import flash.display.Loader;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import flash.system.Capabilities;
class Main extends Sprite
{
private var _bmpData:BitmapData;
private var _bmp:Bitmap;
private var _xmlFileName:String = "data.xml";
public function new()
{
super();
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(event:Event)
{
removeEventListener(Event.ADDED_TO_STAGE, init);
var requestUrl:String = _xmlFileName;
var loader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR, onLoadError);
loader.load(new URLRequest(requestUrl));
}
private function onComplete(event:Event):Void
{
var text:TextField = new TextField();
//text.text = cast(xml,String); //NG
//text.text = data; //OK
text.width = stage.stageWidth;
text.textColor = 0x000000;
text.border = true;
addChild(text);
var data:String = cast(event.currentTarget.data, String);
//var xml:Xml = Xml.parse(data);
var xml:Xml = Xml.parse(data).firstElement();
//trace("xml:"+xml);
//trace("data:"+data);
var fastXml = new haxe.xml.Fast(xml);
//trace(fastXml);
var employee = fastXml.node.employee;
//trace(employee.att.ssn); //123-123-1234
//trace(fastXml.nodes[1].employee.att.ssn); //NG
var zip = employee.node.address.node.zip;
//trace(zip.innerData);//98765
text.text += zip.innerData+"\n";
trace(fastXml.nodes.employee.length); //2
///*
for (elem in fastXml.nodes.employee) {
trace(elem.att.ssn);
text.text += elem.att.ssn+"\n";
}
//*/
}
private function onLoadError(event:IOErrorEvent):Void
{
trace("error occured.");
trace(event.currentTarget.content);
}
}
XmlTest01
\nで改行してくれないな
haxeだとas3のemployee[1]みたいなアクセスはできないんだろうか