Invoice XML¶
Use these APIs to read invoice XML into an invoice model, serialize a finalized invoice, or retrieve the exact XML stored by a signed invoice. For a walkthrough, see invoice signing or validation.
Choose an operation¶
| Operation | Input | Result and behavior |
|---|---|---|
| Parse finalized invoice | Complete invoice XML text or a file path | A finalized invoice with supported fields and calculated totals. Supplied supported amounts are checked against calculations. |
| Parse signed invoice | Complete signed invoice XML text or a file path | A signed invoice containing signature metadata and the exact supplied XML text. Parsing checks the signature, digests and QR against the embedded certificate; issuer trust and clearance remain unverified. |
| Serialize finalized invoice | Finalized invoice | XML text with default two-space indentation. Serialization creates a document from the model; it is not a lossless XML editor. |
| Read signed XML | Signed invoice | Exact stored XML, without formatting changes. Newly signed invoices store the output of signing; imported invoices store the input text. |
| Take signed XML | Signed invoice | Exact stored XML and consumption of the invoice state. |
| Encode signed XML | Signed invoice | Base64 of the stored XML, suitable for APIs that require encoded invoice content. |
Text inputs contain XML, not Base64 or a filename. File variants take a local filesystem path and read its contents as text. Parsing can fail on malformed XML, unsupported or missing required fields, or inconsistent supplied amounts. File operations can also fail when the path cannot be read.
Parsing and serialization do not establish schema conformance, business-rule compliance, or invoice acceptance. Run validation explicitly when needed.
Preserve signed XML¶
Keep returned signed XML unchanged when saving or submitting it. Do not pretty-print, normalize whitespace, or reconstruct it from invoice data. Reading metadata does not change the stored XML. For edits followed by signing, see invoice signing.
Language reference¶
Choose your language for imports, exact calls, returns, and ownership behavior.
Import parsing functions from fatoora_core::invoice::xml::parse and XmlFormat from fatoora_core::invoice::xml.
Parse XML
parse_finalized_invoice_xml(xml: &str) -> Result<FinalizedInvoice, ParseError>
parse_finalized_invoice_xml_file(path: impl AsRef<Path>) -> Result<FinalizedInvoice, ParseError>
parse_signed_invoice_xml(xml: &str) -> Result<SignedInvoice, ParseError>
parse_signed_invoice_xml_file(path: impl AsRef<Path>) -> Result<SignedInvoice, ParseError>
Serialize finalized invoices
FinalizedInvoice::to_xml(&self) -> Result<String, InvoiceXmlError>
FinalizedInvoice::to_xml_with_format(&self, format: XmlFormat) -> Result<String, InvoiceXmlError>
to_xml() uses two spaces of indentation. Choose XmlFormat::Compact for compact output or XmlFormat::Pretty { indent_char: ' ', indent_size: 4 } for explicit indentation. These are inherent methods; no serialization trait import is needed. They borrow the invoice and return a new owned string.
Read signed invoices
SignedInvoice::xml(&self) -> &str
SignedInvoice::into_xml(self) -> String
SignedInvoice::to_xml_base64(&self) -> String
xml() borrows stored XML for the invoice's lifetime. into_xml() consumes the invoice and transfers the stored string without copying. to_xml_base64() returns a new string and leaves the invoice available. Signed invoices have no formatting methods.
Import these functions and invoice types from fatoora.
Parse XML
FinalizedInvoice.from_xml(xml: str) -> FinalizedInvoice
FinalizedInvoice.from_file(path: str | os.PathLike) -> FinalizedInvoice
SignedInvoice.from_xml(xml: str) -> SignedInvoice
SignedInvoice.from_file(path: str | os.PathLike) -> SignedInvoice
Read XML
invoice.xml # property: str
signed.to_xml_base64() -> str
Finalized output uses the default formatting; signed output preserves stored text. String results are independent Python strings and reading them leaves state available. Use context managers or close() for owned objects. Errors raise exceptions; see errors.
Import FinalizedInvoice and SignedInvoice from fatoority. These operations are synchronous and throw a FatooraError subclass on failure.
const finalized = FinalizedInvoice.fromXml(xml);
const signed = SignedInvoice.fromXml(signedXml);
const unsignedText = finalized.xml;
const signedText = signed.xml;
const encoded = signed.toXmlBase64();
const takenText = signed.intoXml();
Both fromXml methods expect a string and return their named invoice object. The xml property and the XML methods are strings. intoXml() consumes the signed invoice state; subsequent access fails. Reading xml or calling toXmlBase64() leaves it available. Read a file using your host environment before passing its text to fromXml; filesystem parsing methods are not exposed in this binding. Finalized formatting is fixed to the default; signed output is exact stored text.
Use Fatoora. Methods throw on failure. Use using to dispose owned invoice objects.
FinalizedInvoice FinalizedInvoice.FromXml(string value)
FinalizedInvoice FinalizedInvoice.FromFile(string value)
SignedInvoice SignedInvoice.FromXml(string value)
SignedInvoice SignedInvoice.FromFile(string value)
string FinalizedInvoice.Xml { get; }
string SignedInvoice.Xml { get; }
string SignedInvoice.IntoXml()
string SignedInvoice.ToXmlBase64()
FromFile takes a local path. Returned strings are independent managed values. IntoXml() consumes invoice state, so further reads fail; disposal remains safe. Other accessors preserve the object. Finalized formatting uses two-space indentation; signed output is exact stored text.
Import com.fatoora.FinalizedInvoice and com.fatoora.SignedInvoice. Methods throw on failure. Close invoice objects with use.
FinalizedInvoice.fromXml(value: String): FinalizedInvoice
FinalizedInvoice.fromFile(value: String): FinalizedInvoice
SignedInvoice.fromXml(value: String): SignedInvoice
SignedInvoice.fromFile(value: String): SignedInvoice
FinalizedInvoice.xml: String
SignedInvoice.xml: String
SignedInvoice.intoXml(): String
SignedInvoice.toXmlBase64(): String
fromFile takes a local path. XML results are independent strings. intoXml() consumes invoice state; later access fails and close() remains safe. Reading xml or toXmlBase64() leaves the invoice available. Finalized output uses default two-space indentation; signed output is exact stored text.
Import com.fatoora.FinalizedInvoice and com.fatoora.SignedInvoice. Use try-with-resources to close invoice objects; methods throw on failure.
FinalizedInvoice FinalizedInvoice.fromXml(String value)
FinalizedInvoice FinalizedInvoice.fromFile(String value)
SignedInvoice SignedInvoice.fromXml(String value)
SignedInvoice SignedInvoice.fromFile(String value)
String FinalizedInvoice.getXml()
String SignedInvoice.getXml()
String SignedInvoice.intoXml()
String SignedInvoice.toXmlBase64()
Static fromFile methods take a local path. String results remain valid after the invoice is closed. intoXml() consumes signed state; later access fails, and closing remains safe. The other accessors preserve state. Finalized output uses two-space indentation; signed output is exact stored text.
Include fatoora.h. All calls below return FatooraStatus and take FatooraError **error as their final argument. Check status before reading an output; free any returned error with fatoora_error_free().
Parse XML
FatooraStatus fatoora_finalized_invoice_from_xml(const char *value,
FatooraFinalizedInvoice **out, FatooraError **error);
FatooraStatus fatoora_finalized_invoice_from_file(const char *value,
FatooraFinalizedInvoice **out, FatooraError **error);
FatooraStatus fatoora_signed_invoice_from_xml(const char *value,
FatooraSignedInvoice **out, FatooraError **error);
FatooraStatus fatoora_signed_invoice_from_file(const char *value,
FatooraSignedInvoice **out, FatooraError **error);
value is a NUL-terminated UTF-8 XML string for _from_xml, or a local path for _from_file. Returned invoice handles are owned; release them with fatoora_finalized_invoice_free() or fatoora_signed_invoice_free().
Read XML
FatooraStatus fatoora_finalized_invoice_xml(const FatooraFinalizedInvoice *self,
char **out, FatooraError **error);
FatooraStatus fatoora_signed_invoice_xml(const FatooraSignedInvoice *self,
char **out, FatooraError **error);
FatooraStatus fatoora_signed_invoice_into_xml(FatooraSignedInvoice *self,
char **out, FatooraError **error);
FatooraStatus fatoora_signed_invoice_to_xml_base64(const FatooraSignedInvoice *self,
char **out, FatooraError **error);
Each output is owned NUL-terminated text; release it with fatoora_string_free(). _xml copies the result and preserves invoice state. _into_xml consumes signed invoice state; further reads fail, but the outer handle must still be freed. _to_xml_base64 returns encoded text without consuming state. Finalized formatting uses two-space indentation; signed output is never reformatted.
See the model preservation contract for supported fields, normalization, rejected structures, and the boundary between model serialization and original signed XML preservation.