So, this is a follow-up question to my previous question that was solved, here's the link to it: using data from child element to select data in other element using simplexml in php
thanks to @RomanPerekhrest for solving this.
I have this piece of php code using simplexml to read my xml file
<?php
$xml = simplexml_load_file('../uploads/reports/report.xml');
$hits = $xml->xpath("results/hits/@rule_id");
$ruleIds = array_map(function($v){ // getting search path for each needed rule
return "profile_info/rules/rule[@id='". (string)$v. "']";
}, $hits);
foreach ($xml->xpath(implode(" | ", $ruleIds)) as $rule) {
echo '<div id="name">'. $rule->display_name .'</div>'.
'<div id="comment">'. $rule->display_comment .'</div>';
}
?>
again, thanks to @RomanPerekhrest for coming up with this.
This piece of code works fine with my simplified xml-file I created to illustrate my problems in my previous questions, but when I apply it, it doesn't seem to render.
I've found the reason why, in my root element there are some xmlns attributes that cause my xml not to load. When I manually remove these attributes, everything works as expected. (I will not the list the entire xml document, since it is 8500+ lines long) Here is the root element with the attributes:
<report xsi:schemaLocation="http://www.callassoftware.com/namespace/pi4 pi4_results_schema.xsd" xmlns="http://www.callassoftware.com/namespace/pi4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
I need a way to bypass in php. Seeing as these xml files are generated by other software and the lack of settings in this generation, I cannot simply make these xml files without these attributes.
Thanks