如何获取下面的代码以输出我定义的节点名称?截至目前,它基于 SQL 表的列名创建节点。我想同时定义列和节点。另外,我如何对其进行编码,以便当有人将数据插入我的表时,它将该数据附加到插入的数据中?例如:
Input data: "davidjmorin"
Data inserted: "http://someurl.com/davidjmorin"
这是我原始问题的代码:
<?
//header('Content-type: text/xml');
$link = mysql_connect('localhost','root','IhaveAlLthEanSwers2012!');
mysql_select_db('bb_links');
$sql = "Select * from `links`";
$run = mysql_query($sql, $link);
if( $run && mysql_num_rows( $run ) ) {
$doc = new DOMDocument( '1.0' );
$doc->formatOutput = true;
$doc->preserveWhiteSpace = true;
$root = $doc->createElement( 'data' );
$doc->appendChild( $root );
while( ( $fetch = mysql_fetch_assoc( $run ) )!== false ) {
$node = $doc->createElement( 'channel' );
$root->appendChild( $node );
foreach( $fetch as $key => $value ) {
createNodes( $key, $value, $doc, $node );
}
}
$doc->save("thelinks.xml");
}
//$node = "channel";
function createNodes( $key, $value, $doc, $node ) {
$key = $doc->createElement( $key );
$node->appendChild( $key );
$key->appendChild( $doc->createTextNode( $value ) );
}
?>