- is zatca app scan qr_code outside of KSA region ?
Answer : NO
- how i can extract qr_code from
clearedInvoice
that returned from success clearance api ?
Answer C# Code
public string ExtractQRCodeValue(string xmlFilePath)
{
try
{
// Load the XML file
XDocument xmlDoc = XDocument.Load(xmlFilePath);
// Define the XML namespaces
XNamespace ns = "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2";
XNamespace cbc = "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2";
XNamespace cac = "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2";
// Find the QR code embedded document
var qrCodeElement = xmlDoc.Descendants(cac + "AdditionalDocumentReference")
.FirstOrDefault(e => (string)e.Element(cbc + "ID") == "QR")
?.Element(cac + "Attachment")
?.Element(cbc + "EmbeddedDocumentBinaryObject");
if (qrCodeElement == null)
{
throw new Exception("QR code not found in the XML.");
}
string base64String = qrCodeElement.Value;
return base64String;
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
return null;
}
}