Thank you for this. I am still getting this error message:
error on line 7 at column 6: XML declaration allowed only at the start of the document
Here is the code we have:
<?php require_once('Connections/sdpc_i.php'); ?>
<?php require_once('webassist/mysqli/rsobj.php'); ?>
<?php require_once('webassist/mysqli/queryobj.php'); ?>
<?php require_once('webassist/mysqli/authentication.php');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL); ?>
<?php
if ("" == "") {
$RestrictAccess = new WA_MySQLi_Auth();
$RestrictAccess->Action = "restrict";
$RestrictAccess->Name = "sdpc_login";
$RestricAccessRedirect = "error.php";
if (function_exists("rel2abs")) $RestricAccessRedirect = $RestricAccessRedirect?rel2abs($RestricAccessRedirect,dirname(__FILE__)):"";
$RestrictAccess->FailRedirect = $RestricAccessRedirect;
$RestrictAccess->execute();
}?>
<?php
$query = new WA_MySQLi_RS("query",$sdpc_i,0);
$query->setQuery("SELECT * from ((SELECT agreement_typesID, agreement_name, state, description, category as thecategory, latest, public, concat('https://sdpc.a4l.org/agreements/',file_pdf) as agreement_file_pdf, concat('https://sdpc.a4l.org/agreements/',file_doc) as agreement_file_doc FROM agreement_types where state = ? and agreement_typesID = ? and category = ?) t1 left join (SELECT * FROM agreement_vendor_types) t8 on (t1.agreement_typesID = t8.agreement_typesID) left join (SELECT * from clause_agreement_type) t2 on (t1.agreement_typesID = t2.agreement_typesID or t2.agreement_type_vendorID = t8.agreement_type_vendorID) left join (SELECT * from contract_clauses) t3 on (t3.clauseID = t2.clauseID) left join (select * from clause_obligation) t4 on (t4.clause_agreement_typeID = t2.clause_agreement_typeID) left join (SELECT * from obligations) t5 on (t5.obligationID = t4.obligationID) left join (SELECT * from obligation_benchmark) t6 on (t4.clause_obligationID = t6.clause_obligationID) left join (SELECT *, benchmarkID as thebenchmarkID from benchmarks) t7 on (t6.benchmarkID = t7.benchmarkID))");
$query->bindParam("s", "".($_GET['state']) ."", "-1"); //state
$query->bindParam("i", "".($_GET['agreement_typesID']) ."", "-1"); //agreement_typesID
$query->bindParam("s", "".($_GET['category']) ."", "-1"); //category
$query->execute();
?>
<?php
function to_xml(SimpleXMLElement $object, array $row) {
foreach ($row as $key => $value) {
if (is_array($value)) {
$new_object = $object->addChild($key);
to_xml($new_object, $value);
} else {
// if the key is an integer, it needs text with it to actually work.
if ($key == (int) $key) {
$key = "$key";
}
$object->addChild($key, $value);
}
}
}
?>
<?php
ob_start();
while (!$query->atEnd()) {
$xml = new SimpleXMLElement('<data/>');
to_xml($xml, $query->Results[$query->Index]);
print $xml->asXML();
$query->moveNext();
}
$output = ob_get_contents();
ob_end_clean();
header('Content-Type: application/xml; charset=utf-8');
header('Content-Language: en');
header('Cache-Control: no-store, no-cache, must-revalidate');
header("Content-Length: ".strlen($output));
header("Date: ".gmdate('D, d M Y H:i:s T'));
echo($output);
?>