XMLInvoice

Check the type of XML document and throw an exception if invalid
This commit is contained in:
sparkyx 2025-11-29 09:01:53 +01:00
parent 22ec6c8029
commit 427eb77fd9
2 changed files with 13 additions and 1 deletions

View file

@ -35,6 +35,7 @@ namespace Noalyss\XMLDocument;
* Exception code :
* - 55 : XML Invalid
* - 62 : filename don't exist
* - 140: not a credit note
* Namespace standard (from XSD)
*
* Array
@ -135,6 +136,10 @@ class XMLCreditNote_Reader extends XML_Reader
{
$result = [];
$node = $this->get_node("//cac:CreditNoteLine");
if ($node == null )
{
throw new \Exception ("XC140 invalide document",140);
}
for ($e = 0; $e < $node->length; $e++)
{
$row = [];

View file

@ -34,6 +34,7 @@ namespace Noalyss\XMLDocument;
* Exception code :
* - 55 : XML Invalid
* - 62 : filename don't exist
* - 143 : not an invoice
* Namespace standard (from XSD)
*
* Array
@ -100,6 +101,12 @@ class XMLInvoice_Reader extends XML_Reader
{
$result = [];
$node = $this->get_node("//cac:InvoiceLine");
// read Invoice
if ( $node == null )
{
throw new \Exception ("XR143 unknow document",143);
}
for ($e = 0; $e < $node->length; $e++)
{
$row = [];
@ -113,9 +120,9 @@ class XMLInvoice_Reader extends XML_Reader
$row ['tva_percent'] = $this->get_node_value("//cac:InvoiceLine/cac:Item/cac:ClassifiedTaxCategory/cbc:Percent", $e);
$result[] = $row;
}
return $result;
}
}
/**
* @brief return the code of the document
* @return string invoice + code