Possible Duplicate:
How to parse HTML with PHP?
Get MySQL database output via PHP to XML可能重复:如何使用PHP解析HTML?通过PHP获取MySQL数据库输出到XML
I have some tables in MySQL.... Can I use PHP to create a .xml file on my website that will neatly contain the information from my MySQL database?
我在MySQL中有一些表....我可以使用PHP在我的网站上创建一个.xml文件,它将整齐地包含我的MySQL数据库中的信息吗?
On a side note if I am retrieving xml information in action script 2.0 do I HAVE to retrieve it from a .xml file or can I have a .php file that creates an open and close tag on the page and then creates an xml table on the .php page?
另外,如果我在动作脚本2.0中检索xml信息,我是否必须从.xml文件中检索它,或者我是否有一个.php文件在页面上创建一个打开和关闭标记,然后创建一个xml表.php页面?
2 个解决方案
#1
1
you can create XML in PHP and you can save it as file or echo as XML string , you can use below sample codes
你可以用PHP创建XML,你可以将它保存为文件或echo作为XML字符串,你可以使用下面的示例代码
$xml = new DOMDocument('1.0', 'iso-8859-1');
$rootNode = $xml->createElement('xmlrootnode');
$rootNode = $xml->appendChild($rootNode);
foreach( $resultArr as $r ) {
$sDateArr = explode( ' ', $r['start_time'] );
$sRootN = $xml->createElement('date');
$sRootN = $rootNode->appendChild($sRootN);
$sRootN->setAttribute('value', $sDateArr[0]);
//Id field
$idN = $xml->createElement('id');
$idN = $sRootN->appendChild($idN);
$idT = $xml->createTextNode(htmlentities($r['id']));
$idN->appendChild($idT);
}
//$xml->save($xml);
//header('Content-type: text/xml');
//echo $xmlStr = $xml->saveXML();
$xmlStr = isset($xml) ? htmlspecialchars($xml->saveXML()) : '';
#2
1
As an answer to your side note:
Yes you can - thats the normal way to do it.
AS does not even know if it was a file or created on the fly - it just receives the data and if it is valid XML it should work...
作为你的旁注的答案:是的,你可以 - 这是正常的做法。 AS甚至不知道它是文件还是动态创建 - 它只是接收数据,如果它是有效的XML它应该工作...
#1
1
you can create XML in PHP and you can save it as file or echo as XML string , you can use below sample codes
你可以用PHP创建XML,你可以将它保存为文件或echo作为XML字符串,你可以使用下面的示例代码
$xml = new DOMDocument('1.0', 'iso-8859-1');
$rootNode = $xml->createElement('xmlrootnode');
$rootNode = $xml->appendChild($rootNode);
foreach( $resultArr as $r ) {
$sDateArr = explode( ' ', $r['start_time'] );
$sRootN = $xml->createElement('date');
$sRootN = $rootNode->appendChild($sRootN);
$sRootN->setAttribute('value', $sDateArr[0]);
//Id field
$idN = $xml->createElement('id');
$idN = $sRootN->appendChild($idN);
$idT = $xml->createTextNode(htmlentities($r['id']));
$idN->appendChild($idT);
}
//$xml->save($xml);
//header('Content-type: text/xml');
//echo $xmlStr = $xml->saveXML();
$xmlStr = isset($xml) ? htmlspecialchars($xml->saveXML()) : '';
#2
1
As an answer to your side note:
Yes you can - thats the normal way to do it.
AS does not even know if it was a file or created on the fly - it just receives the data and if it is valid XML it should work...
作为你的旁注的答案:是的,你可以 - 这是正常的做法。 AS甚至不知道它是文件还是动态创建 - 它只是接收数据,如果它是有效的XML它应该工作...