Read xml with DOMDocument PHP

0

I have xml like this:

<pai a='1'>
  <filha>
    <codigo>1</codigo>
  </filha>
  <outrafilha>
    <codigo>2</codigo>
  </outrafilha>
</pai>
<pai a='2'>
  <filha>
    <codigo>3</codigo>
  </filha>
  <outrafilha>
    <codigo>4</codigo>
  </outrafilha>
</pai>  

I want to know how to read daughters and get the code and all daughters have different names, but the field name will always be code.

I'm reading parents like this:

$DOMDocument = new DOMDocument('1.0', 'UTF-8');
$DOMDocument->preserveWhiteSpace = false;
$DOMDocument->loadXML($blob);
$produtos = $DOMDocument->getElementsByTagName('pai');
foreach($produtos as $produto) 
{

}
    
asked by anonymous 28.05.2018 / 00:35

0 answers