Somthing wrong here, dont seem to be able to merge XML DOMDocumet's I get the error, "Fatal error: Call to undefined method DOMElement::importNode() in C:\xampp\htdocs\xmltest\xmltest.php on line 27" can anybody help me put this code right...
<?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('tblc开发者_开发问答lients'));
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();
}
?>
importNode()
is a method belonging to the document, not an element. You want to import into the document ($dom
) then append to the element ($tblclients
).
A node is needed when importing (and $tblclientsXML
is not a node, it's a document) so importing the generated XML would look similar to:
$tblclientsElement = $tblclientsXML->documentElement;
$tblclientsXML = $dom->importNode($tblclientsElement, TRUE);
$tblclients->appendChild($tblclientsXML);
精彩评论