这里的错误,似乎无法合并XML DOMDocumet我得到错误,“致命错误:在C:\ xampp \ htdocs \ xmltest \ xmltest.php中调用未定义的方法DOMElement :: importNode() 27“任何人都可以帮我把这个代码弄好......
<?php
// include required files
include 'XML/Query2XML.php';
include 'MDB2.php';
// prepare xml document
$dom = new DomDocument('1.0');
// create tables section
$tables = $dom->appendChild($dom->createElement('tables'));
// create container for tblclients
$tblclients = $tables->appendChild($dom->createElement('tblclients'));
try {
// initialize Query2XML object
$q2x = XML_Query2XML::factory(MDB2::factory('mysql://root:@localhost/db_solconmgr'));
// generate SQL query
$sql = "SELECT ClientID, Client, Contacts, 'Address Line 1' as AddressLine1, 'Address Line 2' as AddressLine2, City, County, 'Zip Code' as ZipCode, Telephone, Fax, Mobile, 'E-mail Address' as EmailAddress, Date FROM tblclients";
// get results as XML
$tblclientsXML = $q2x->getFlatXML($sql);
//$dom = $tblclientsXML;
$node = $tblclients->importNode($tblclientsXML, true);
// send output to browser
header('Content-Type: text/xml');
$dom->formatOutput = true;
echo $dom->saveXML();
} catch (Exception $e) {
echo $e->getMessage();
}
?>
答案 0 :(得分:4)
importNode()
是属于文档的方法,而不是元素。您想要导入文档($dom
),然后附加到元素($tblclients
)。
导入时需要节点(并且$tblclientsXML
不是节点,它是文档),因此导入生成的XML看起来与类似:< / p>
$tblclientsElement = $tblclientsXML->documentElement;
$tblclientsXML = $dom->importNode($tblclientsElement, TRUE);
$tblclients->appendChild($tblclientsXML);