Dear All,
I am working on an XML parser. However, I now am stuck on getting the values only in case no namespaces are set for a certain node, or when the namespace is set to xml:lang="en". I have no idea how to get this working.
I am now using these two functions:
// one example file:
$xmlUrl = http://www.utwente.nl/master/hodexdata/?get=BK
function get_programme_info4($xmlUrl)
{
// ensure right URL
echo $xmlUrl."<br />";
// Load the document
$dom = new DomDocument();
$dom->load($xmlUrl);
// get tuition fee
$TuitionInfo = get_node_info($dom, 'tuitionFee', array('amount', 'period', 'programForm', 'year'));
// Get programme info
$ProgrammeInfos = get_node_info($dom, 'programDescriptions', array('programName', 'programDescription'));
}
function get_node_info($dom, $NodeName, $fields)
{
// http://www.php.net/manual/en/domdocument.getelementbyid.php
$out = array();
$params = $dom->getElementsByTagName($NodeName);
$k=0;
foreach($params as $p)
{
echo "<p>";
$sub = array();
foreach($fields as $field)
{
echo $field;
/* The following line works. However, when multiple languages are defined, this is typically not the right one. So try to get namespaces involved. Then however it fails.
*/
// $nodes = $params->item($k)->getElementsByTagName($field);
$nodes = $params->item($k)->getElementsByTagNameNS('xml:lang="en"', $field);
$sub[$field] = $nodes->item(0)->nodeValue;
echo "<br />".$sub[$field];
}
echo "</p>";
$k++;
}
}
The errors I get with this script:
http://www.utwente.nl/master/hodexdata/?get=BK
amount
Notice: Trying to get property of non-object in C:\xampp\htdocs\degrees\includes\functions\hodex\hodex_index_functions.php on line 213
period
Notice: Trying to get property of non-object in C:\xampp\htdocs\degrees\includes\functions\hodex\hodex_index_functions.php on line 213
programForm
Notice: Trying to get property of non-object in C:\xampp\htdocs\degrees\includes\functions\hodex\hodex_index_functions.php on line 213
year
Notice: Trying to get property of non-object in C:\xampp\htdocs\degrees\includes\functions\hodex\hodex_index_functions.php on line 213
etc...