您的位置:首页 > 编程语言 > PHP开发

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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: