У меня возникла проблема при попытке прочитать XML-файл из системного файла ro e-Factura с помощью php с помощью этой функции: [code]function parseXMLFactura($path_xml) { if (!file_exists($path_xml)) { return []; }
if ($documentType == 'CreditNote') { $lineType = 'cac:CreditNoteLine'; }
$products = [];
foreach ($xml->xpath('//' . $lineType) as $line) { $product = []; $product['denumire'] = (string)$line->xpath('cac:Item/cbc:Name')[0]; $product['cod_produs'] = (string)$line->xpath('cac:Item/cbc:Description')[0]; if (empty($product['cod_produs'])) { $product['cod_produs'] = $product['denumire']; } $product['cantitate'] = (string)$line->xpath('cbc:InvoicedQuantity')[0]; if (empty($product['cantitate'])) { $product['cantitate'] = (string)$line->xpath('cbc:CreditedQuantity')[0]; } $product['pret_buc'] = (string)$line->xpath('cac:Price/cbc:PriceAmount')[0]; $product['val_tva'] = (string)$line->xpath('cac:Item/cac:ClassifiedTaxCategory/cbc:Percent')[0]; $product['pret_raft'] = '0'; // Valoare implicită, actualizată ulterior dacă e cazul $product['unitate_masura'] = (string)$line->xpath('cbc:InvoicedQuantity/@unitCode')[0]; if (empty($product['unitate_masura'])) { $product['unitate_masura'] = (string)$line->xpath('cbc:CreditedQuantity/@unitCode')[0]; }
// Invert values for CreditNote with type code 381 if ($documentType == 'CreditNote' && $creditNoteTypeCode == '381') { $product['cantitate'] = '-' . $product['cantitate']; //$product['pret_buc'] = '-' . $product['pret_buc']; }
$products[] = $product;
// Verificăm dacă există discounturi foreach ($line->xpath('cac:AllowanceCharge') as $allowanceCharge) { if ((string)$allowanceCharge->xpath('cbc:ChargeIndicator')[0] === 'false') { $discount = []; $discount['denumire'] = (string)$allowanceCharge->xpath('cbc:AllowanceChargeReason')[0]; $discount['cod_produs'] = $discount['denumire']; // Denumirea este folosită ca și cod produs pentru discount $discount['cantitate'] = '-1'; $discount['pret_buc'] = (string)$allowanceCharge->xpath('cbc:Amount')[0]; $discount['val_tva'] = (string)$line->xpath('cac:Item/cac:ClassifiedTaxCategory/cbc:Percent')[0]; $discount['pret_raft'] = '0'; $discount['unitate_masura'] = '';
// Invert discount amount for CreditNote with type code 381 if ($documentType == 'CreditNote' && $creditNoteTypeCode == '381') { $discount['pret_buc'] = '-' . $discount['pret_buc']; }
$products[] = $discount; } } }
return $products; } [/code] я получаю:
Предупреждение: SimpleXMLElement::xpath(): неопределенный префикс пространства имен
может кто-нибудь помочь мне понять, почему? для одного XML-файла работает, для другого появляется ошибка