日期:2014-05-17 浏览次数:20432 次
// 引用数据库处理文件 require_once "../../DBHandle/DBHandle/DBUser.php"; $lefNav = $_REQUEST ["lefNav"]; $action = $_REQUEST ["action"]; if ($lefNav == "userinfo") { if (action == "init") { $userId = $_REQUEST ['user_id']; $rs = DBUser::getUserInfoByID ( $userId ); if ($rs) { // 将查询出来的用户信息结果放置到XML中传到前段 $doc = new DOMDocument ( "1.0", "utf-8" ); $doc->appendChild ( $doc->createElement ( "xml" ) ); $userNode = $doc->createElement ( "rs" ); $userId = $doc->createElement ( "userId" ); $userIdTx = $doc->createTextNode($rs[0]); $userId->appendChild($userIdTx); $name = $doc->createElement ( "name" ); $nameTx = $doc->createTextNode($rs[1]); $name->appendChild($nameTx); $rname = $doc->createElement ( "rname" ); $rnameTx = $doc->createTextNode($rs[2]); $rname->appendChild($rnameTx); $gname = $doc->createElement ( "gname" ); $gnameTx = $doc->createTextNode($rs[3]); $gname->appendChild($gnameTx); $userNode->appendChild($userId); $userNode->appendChild($name); $userNode->appendChild($rname); $userNode->appendChild($gname); $doc->documentElement->appendChild($userNode); echo $doc->saveXML(); } else { echo "FAIL"; } } }
include(dirname(__FILE__)."/xmlparse.php"); $listtags = explode(" ","2 name"); $arr = array(1,"name"=>"SOM","admin",100,array("name"=>"TOM","Lily")); $contXML = dump_xml_config($arr, "xml", "utf-8"); //放入文件 //file_put_contents_safe("/path/test.xml",$contXML,"w"); echo $contXML; #源码 #<?xml version="1.0" encoding="utf-8"?> #<xml> # <0>1</0> # <name>SOM</name> # <1>admin</1> # <2>100</2> # <3> # <name>TOM</name> # <0>Lily</0> # </3> #</xml>