实际上,我正在使用谷歌地图定位器我需要domxml新的doc功能所以如何创建这个功能请帮我解决这个问题。 我的问题如下:致命错误:在第58行调用未定义的函数domxml_new_doc()
这里是我的代码:
require("db_connection.php");
// Start XML file, create parent node
$doc = domxml_new_doc("1.0");
$node = $doc->create_element("tbl_master_property");
$parnode = $doc->append_child($node);
// Opens a connection to a MySQL server
$connection=mysql_connect ('localhost', $username, $password);
if (!$connection) {
die('Not connected : ' . mysql_error());
}
// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
// Select all the rows in the markers table
$query = "SELECT * FROM markers WHERE 1";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// Add to XML document node
$node = $doc->create_element("tbl_master_property");
$newnode = $parnode->append_child($node);
$newnode->set_attribute("id", $row['id']);
$newnode->set_attribute("name", $row['name']);
$newnode->set_attribute("address", $row['address']);
$newnode->set_attribute("lat", $row['lat']);
$newnode->set_attribute("lng", $row['lng']);
$newnode->set_attribute("type", $row['type']);
}
$xmlfile = $doc->dump_mem();
echo $xmlfile;
答案 0 :(得分:1)
使用mysqli
和DOMDocument
您应该可以对以下内容执行相同操作 - 但未经过测试。
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpwd = 'xxx';
$dbname = 'xxx';
$db = new mysqli( $dbhost, $dbuser, $dbpwd, $dbname );
$sql='select * from `markers`;';
$result=$db->query( $sql );
$attribs=array('id','name','address','lat','lng','type');
$dom=new DOMDocument('1.0','utf-8');
$dom->formatOutput=true;
$dom->standalone=true;
$dom->recover=true;
$root=$dom->createElement('tbl_master_property');
$dom->appendChild( $root );
while( $rs=$result->fetch_object() ){
$node=$dom->createElement('property');
$root->appendChild( $node );
foreach( $attribs as $attrib ){
$attr = $dom->createAttribute( $attrib );
$value= $dom->createTextNode( $rs->$attrib );
$attr->appendChild( $value );
$node->appendChild( $attr );
}
}
header("Content-Type: application/xml");
echo $dom->saveXML();
?>