SimpleXML tags with – in the name

Sometimes a xml file will have tags with “-“s in the name.
It is not to hard to parse this using simplexml, just use the tagname inside curly brackets like: “{tag-name}”

<?xml version="1.0" encoding="utf-8"?>
<medprod xmlns:npl="urn:schemas-instance" version="129">
  <statuses>
    <mpa_status xmlns:mpa="urn:schemas-mpa" datastatus="valid" procstatus="reviewed"/>
  </statuses>
  <mpa_pharmaceutical-form-group-lx xmlns:mpa="urn:schemas-mpa" v="OSD"/>
</medprod>

Let’s assume we load the above in a SimpleXML object called $simplemedprodXml

$simplemedprodXml= simplexml_load_string($xmlString);
echo (string)$simplemedprodXml['version'];
echo (string)$simplemedprodXml->statuses->mpa_status['datastatus'];
echo (string)$simplemedprodXml->statuses->mpa_status['procstatus'];
echo (string)$simplemedprodXml->{'mpa_pharmaceutical-form-group-lx'}['v'];