So for starters, you're working with invalid XML. It should look something like this:
<?xml version="1.0" encoding="utf-8"?>
<cfdi:Comprobante xmlns:cfdi="https://some/uri">
<cfdi:Conceptos>
<cfdi:Concepto cantidad="1.00" unidad="PZA" noIdentificacion="RRGARACION" descripcion="51571 CADENA ORO AMRILLO 45CMTS FAVOR DE SOLDAR EL ESLABON DE LADO DEL BROCHE" valorUnitario="81.90" importe="81.90" />
<cfdi:Concepto cantidad="1.00" unidad="PZA" noIdentificacion="RRGARACION" descripcion="51570 CADENA ORO BLANCO C/CORAZON FAVOR DE SOLDAR A 16 CMTS DEL BROCHE" valorUnitario="206.90" importe="206.90" />
</cfdi:Conceptos>
<cfdi:Impuestos>
<cfdi:Traslados>
<cfdi:Traslado impuesto="IVA" tasa="16" importe="46.20" />
</cfdi:Traslados>
</cfdi:Impuestos>
</cfdi:Comprobante>
(Note the xmlns
attribute and the correct closing slashes.)
Next, you're calling a function getpath
which came from where? I don't know. But you're passing it an invalid XPath query. You're looking for the attribute of the Traslados
element when you want the Traslado
element instead. Try this out:
$xml = <<< XML
<?xml version="1.0" encoding="utf-8"?>
<cfdi:Comprobante xmlns:cfdi="https://some/uri">
<cfdi:Conceptos>
<cfdi:Concepto cantidad="1.00" unidad="PZA" noIdentificacion="RRGARACION" descripcion="51571 CADENA ORO AMRILLO 45CMTS FAVOR DE SOLDAR EL ESLABON DE LADO DEL BROCHE" valorUnitario="81.90" importe="81.90" />
<cfdi:Concepto cantidad="1.00" unidad="PZA" noIdentificacion="RRGARACION" descripcion="51570 CADENA ORO BLANCO C/CORAZON FAVOR DE SOLDAR A 16 CMTS DEL BROCHE" valorUnitario="206.90" importe="206.90" />
</cfdi:Conceptos>
<cfdi:Impuestos>
<cfdi:Traslados>
<cfdi:Traslado impuesto="IVA" tasa="16" importe="46.20" />
</cfdi:Traslados>
</cfdi:Impuestos>
</cfdi:Comprobante>
XML;
$doc = new DomDocument();
$doc->loadXML($xml);
$xp = new DOMXpath($doc);
$xp->registerNamespace("cfdi", "https://some/uri");
$nodes = $xp->query("//cfdi:Traslados/*[@impuesto='IVA']/@importe");
foreach ($nodes as $node) {
var_dump($node->nodeValue);
}