flash 读XML 和 PHP 写XML
2013-06-26 17:08
197 查看
<?php
define("HOST","localhost");
define("USER","root");
define("PASS","root");
define("DATABASE","book");
$Conn=mysql_connect(HOST,USER,PASS) or die("连接数据库服务器失败,请联系管理员!");
mysql_query("set names utf8");
mysql_select_db(DATABASE,$Conn) or die("连接数据库失败,请联系管理员检查数据库配置!");
$sql="select * From book";
$R = mysql_query($sql,$Conn) or die("22");
//$l0=$dom->createElement('root');//创建一个root的元素
//$ab=$dom->createAttribute('id');//创建一个id的属性元素
//$ab->nodeValue="001";//给这个属性赋值为001
//$l0->setAttributeNode($ab);//将这个属性追加到元素root上去
$doc = new DOMDocument('1.0','UTF-8');
$doc->formatOutput=true;//忽视多余空格为一个
$r=$doc->createElement("books");
$doc->appendChild($r);
$i=1;
while($Row=mysql_fetch_array($R,MYSQL_ASSOC)){
$b=$doc->createElement("book");
$ab=$docss->createAttribute("id");
$ab->nodeValue=$i;
$b->setAttributeNode($ab);
//$author=$doc->createElement("author");
//$author->appendChild($doc->createTextNode("aa"));
$author=$doc->createElement("author",$Row['author']);
$b->appendChild($author);
//$title=$doc->createElement("title");
//$title->appendChild($doc->createTextNode("bb"));
$title=$doc->createElement("title",$Row['title']);
$b->appendChild($title);
//$publisher=$doc->createElement("publisher");
//$publisher->appendChild($doc->createTextNode("cc"));
$publisher=$doc->createElement("publisher",$Row['publisher']);
$b->appendChild($publisher);
$r->appendChild($b);
$i++;
}
//$filenamed="D:\win7我的文档-桌面-收藏夹\Desktop\test.XML";
$filenamed="test.XML";
$doc->save($filenamed);
//$doc->saveXML();
?>
flash 读XML:
urlloader.load(new URLRequest("config.xml"));
urlloader.addEventListener(Event.COMPLETE,Loadxml);
function Loadxml(e:Event) {
var xml:XML=XML(urlloader.data);
ptmax=xml.child(0).child(0).child(0);//
}
XML 文档:
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book id="1">
<author>aa</author>
<title>bb</title>
<publisher>cc</publisher>
</book>
<book id="2">
<author>aa2</author>
<title>bb2</title>
<publisher>cc2</publisher>
</book>
</books>
define("HOST","localhost");
define("USER","root");
define("PASS","root");
define("DATABASE","book");
$Conn=mysql_connect(HOST,USER,PASS) or die("连接数据库服务器失败,请联系管理员!");
mysql_query("set names utf8");
mysql_select_db(DATABASE,$Conn) or die("连接数据库失败,请联系管理员检查数据库配置!");
$sql="select * From book";
$R = mysql_query($sql,$Conn) or die("22");
//$l0=$dom->createElement('root');//创建一个root的元素
//$ab=$dom->createAttribute('id');//创建一个id的属性元素
//$ab->nodeValue="001";//给这个属性赋值为001
//$l0->setAttributeNode($ab);//将这个属性追加到元素root上去
$doc = new DOMDocument('1.0','UTF-8');
$doc->formatOutput=true;//忽视多余空格为一个
$r=$doc->createElement("books");
$doc->appendChild($r);
$i=1;
while($Row=mysql_fetch_array($R,MYSQL_ASSOC)){
$b=$doc->createElement("book");
$ab=$docss->createAttribute("id");
$ab->nodeValue=$i;
$b->setAttributeNode($ab);
//$author=$doc->createElement("author");
//$author->appendChild($doc->createTextNode("aa"));
$author=$doc->createElement("author",$Row['author']);
$b->appendChild($author);
//$title=$doc->createElement("title");
//$title->appendChild($doc->createTextNode("bb"));
$title=$doc->createElement("title",$Row['title']);
$b->appendChild($title);
//$publisher=$doc->createElement("publisher");
//$publisher->appendChild($doc->createTextNode("cc"));
$publisher=$doc->createElement("publisher",$Row['publisher']);
$b->appendChild($publisher);
$r->appendChild($b);
$i++;
}
//$filenamed="D:\win7我的文档-桌面-收藏夹\Desktop\test.XML";
$filenamed="test.XML";
$doc->save($filenamed);
//$doc->saveXML();
?>
flash 读XML:
urlloader.load(new URLRequest("config.xml"));
urlloader.addEventListener(Event.COMPLETE,Loadxml);
function Loadxml(e:Event) {
var xml:XML=XML(urlloader.data);
ptmax=xml.child(0).child(0).child(0);//
}
XML 文档:
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book id="1">
<author>aa</author>
<title>bb</title>
<publisher>cc</publisher>
</book>
<book id="2">
<author>aa2</author>
<title>bb2</title>
<publisher>cc2</publisher>
</book>
</books>
相关文章推荐
- php5&Flash as2操作xml
- asp/php/.net/+flash+XML的动态曲线图/饼状图/矩形图(转)
- PHP 生成的XML以FLASH获取为乱码终极解决
- PHP 生成的XML以FLASH获取为乱码终极解决
- 无论是php java后台服务器在域名的根目录添加 crossdomian.xml文件实现flash 安全策略,从而实现通讯
- 利用Flash AS2.0实现读取php xml数据和插入记录
- PHP 生成的XML以FLASH获取为乱码终极解决
- PHP 生成的XML以FLASH获取为乱码终极解决
- FLASH调用XML数据简明教程
- PHP 自学之路-----XML基本语法及DTD介绍
- 用Flash和XML构建论坛实例(4)
- php 解析XML的几种方式
- flash用XML与java通信
- FLASH+XML教程(适用于AS2.0)
- php中使用getimagesize获取图片、flash等文件的尺寸信息实例
- php 解析xml 的四种方法(转)
- PHP使用DOMDocument 操作xml
- PHP动态生成xml
- 关于xml编码问题在VB,PHP,JAVA下的解决方案
- php+ajax+xml在服务器和客户端之间多次交互数据