0
xml出力をエコーすると、タイトルにエラーが表示されます。私は何を忘れましたか? 開始タグは正しくありませんか?誰かがこのコードで私を助けてくれることを願っています。XML出力:名前が無効な文字で始まった
私は事前にウェブサイトhttp://www.mightywebdeveloper.com/coding/mysql-to-xml-php/
ありがとうからの指示に従いました。
<?php
$config['table_name'] = "tblPortalStatus";
//database configuration
$serverName = "servername";
$connectionInfo = array(all info here);
$conn = sqlsrv_connect($serverName, $connectionInfo);
$sql = "SELECT * FROM tblPortalStatus";
$params = array();
$options = array("Scrollable" => SQLSRV_CURSOR_KEYSET);
$result = sqlsrv_query($conn, $sql, $params,$options);
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
$root_element = $config['table_name']."s"; //tblPortalStatus
$xml .= "<$root_element>";
if (!sqlsrv_num_rows($result)) {
die('Invalid query: ' . sqlsrv_error());
}
if(sqlsrv_num_rows($result)>0)
{
while($result_array = sqlsrv_fetch_array($result))
{
$xml .= "<".$config['table_name'].">";
//loop through each key,value pair in row
foreach($result_array as $key => $value)
{
//$key holds the table column name
$xml .= "<$key>";
//embed the SQL data in a CDATA element to avoid XML entity issues
$xml .= "<![CDATA[$value]]>";
//and close the element
$xml .= "</$key>";
}
$xml.= "</".$config['table_name'].">";
}
}
//close the root element
$xml .= "</$root_element>";
//send the xml header to the browser
header ("Content-Type:text/xml");
//output the XML data
echo $xml;
?>
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------
A name was started with an invalid character. Error processing resource 'http://PHP/Form.php'. Line 37, ...
<?xml version="1.0" encoding="UTF-8"?><tblPortalStatuss><tblPortalStatus><0><![CDATA[EPRC]]>&l...