Ive been having a problem with my php using xml ive gone through it for so long I still cant seem to find the error: Heres my php:
<?php
$VacancyDetailsRequest = simplexml_load_string($HTTP_RAW_POST_DATA);
if (!$VacancyDetailsRequest)
die("invalid request XML: if you sent XML did you set the request header to 'Content-Type', 'text/xml' ?");
if (file_exists('vacancies.xml')) {
$details = simplexml_load_file('vacancies.xml');
if ($details) {
getVacancyDetails($details, $VacancyDetailsRequest->accountNumber);
} else {
die('vacancies.xml not well formed');
}
} else
{
die('Failed to open vacancies.xml.');
}
function getVacancyDetails($details, $accountNumber) {
foreach ($details->vacancy as $vacancy) {
if ((string)$vacancy->title == (string)$accountNumber) {
foreach($vacancy->title as $company) {
echo "<p>";
echo htmlentities($company->asXML());
echo "</p>";
}
}
}
}
?>
and heres my javascript for it:
function getVacancyDetails(accountNumber) {
var myDivId = "vacancyId";
var myData = "hello";
var xml = "<?xml version='1.0' ?>";
xml = xml + "<VacancyDetailsRequest xmlns='http://cs.waikato.ac.nz/~ap65/333/jobs/requests'><accountNumber>";
xml = xml + myData;
xml = xml + "</accountNumber></VacancyDetailsRequest>";
ajaxRequest("getVacancyDetails.php", "POST", xml, true, showVacancy, true, myDivId);
}
function showVacancy(response, VacancyListDiv) {
var VacancyListDiv = document.getElementById("VacancyListDiv");
VacancyListDiv.innerHTML = response;
}
just in case heres my xml
<?xml version = "1.0"?>
<vacancies xmlns="http://www.cs.waikato.ac.nz/ap65/vacancies/vacancy">
<vacancy>
<vid>VAC-2009-03-20-087</vid>
<title>Assistant</title>
<description>A job for an assistant</description>
<company>Fairfax</company>
<type>contract</type>
<category>Engineering</category>
<location>Hamilton</location>
<salary>65,000</salary>
<eid>EMP-298756</eid>
</vacancy>
<vacancy>
<vid>VAC-2003-04-30-098</vid>
<title>Admininstrator</title>
<description>Working as the administrator</description>
<company>Unisys</company>
<type>permanent</type>
<category>IT</category>
<location>Aucklad</location>
<salary>28,000</salary>
<eid>EMP-123456</eid>
</vacancy>
<vacancy>
<vid>VAC-2009-05-09-076</vid>
<title>Customer Service</title>
<description>Be able to communicate with customers</description>
<company>Southern Cross</company>
<type>contract</type>
<category>Engineering</category>
<location>Hamilton</location>
<salary>15,000</salary>
<eid>EMP-654321</eid>
</vacancy>
<vacancy>
<vid>VAC-2007-10-06-051</vid>
<title>Maintenance</title>
<description>Maintenance of all manufacturing equipment</description>
<company>Drake Industrial</company>
<type>permanent</type>
<category>Engineering</category>
<location>Hamilton</location>
<salary>40,000</salary>
<eid>EMP-789654</eid>
</vacancy>
</vacancies>