Hi everyone I have this XML structure and I would like to get the value of the IdDocumento attributes
<pago10:Pagos>
<pago10:Pago>
<pago10:DoctoRelacionado IdDocumento="B670AD5D-8BA6-42CF-A0D0-1A403E042FBA" />
</pago10:Pago>
<pago10:Pago>
<pago10:DoctoRelacionado IdDocumento="B670AD5D-8BA6-42CF-A0D0-1A403E042FBA" />
<pago10:DoctoRelacionado IdDocumento="842b32ce-44c1-4b31-96b8-3a34569c698c" />
</pago10:Pago>
</pago10:Pagos>
I have tried with this as follow:
$xml = simplexml_load_file('complemento.xml');
$ns = $xml->getNamespaces(true);
$xml->registerXPathNamespace('p', $ns['pago10']);
if ($xml->xpath('//p:Pagos')) {
foreach ($xml->xpath('//p:Pagos') as $pagos10) {
foreach ($xml->xpath('//p:Pago') as $pago10) {
foreach ($xml->xpath('//p:DoctoRelacionado') as $doc) {
echo $doc['IdDocumento'] . '<br>';
}
echo "=========================================";
}
}
}
But this is displaying the 3 attributes IdDocumento at once I was hoping to print the first
attribute IdDocumento and make the separator and then print the other two, how can I know which
IdDocumento belongs to every pago10:Pago node?
Expected result:
B670AD5D-8BA6-42CF-A0D0-1A403E042FB
====================================
B670AD5D-8BA6-42CF-A0D0-1A403E042FBA
842b32ce-44c1-4b31-96b8-3a34569c698c
What I'm getting:
B670AD5D-8BA6-42CF-A0D0-1A403E042FB
B670AD5D-8BA6-42CF-A0D0-1A403E042FBA
842b32ce-44c1-4b31-96b8-3a34569c698c
====================================
B670AD5D-8BA6-42CF-A0D0-1A403E042FB
B670AD5D-8BA6-42CF-A0D0-1A403E042FBA
842b32ce-44c1-4b31-96b8-3a34569c698c