I have a XML file which I want to replace a value with a constant when it is empty, checking an attribute (annotation_ref). The XML tags are something like this:
<ANNOTATION> <REF_ANNOTATION ANNOTATION_ID="id" ANNOTATION_REF="1234"> <ANNOTATION_VALUE></ANNOTATION_VALUE> </REF_ANNOTATION> </ANNOTATION> So, the result of the transformation would be:
<ANNOTATION> <REF_ANNOTATION ANNOTATION_ID="id" ANNOTATION_REF="1234"> <ANNOTATION_VALUE>my_constant</ANNOTATION_VALUE> </REF_ANNOTATION> </ANNOTATION> But instead of that, I get this:
<ANNOTATION> <REF_ANNOTATION ANNOTATION_ID="id" ANNOTATION_REF="1234"> <ANNOTATION_VALUE/> </REF_ANNOTATION> <ANNOTATION_VALUE>my_constant</ANNOTATION_VALUE></ANNOTATION> My code is the next:
$document = simplexml_load_file("my_document.eaf"); $aux = $annotation_document->ANNOTATION; foreach ($aux as $aux2) { if ($aux2->REF_ANNOTATION->attributes()->ANNOTATION_REF == $my_condition) { $aux2->ANNOTATION_VALUE = $my_constant; } } Thank you so much.