Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sandhiya PriyaRank #26 · 43.2K reputationPosted Nov 6, 2025, 3:46 AM EST
To create an XML document in C# for Fiskalizacija 2.0 (a Croatian fiscalization standard used for generating fiscal receipts), you'll need to construct the XML with the appropriate structure according to the Fiskalizacija 2.0 specifications. The XML document will usually contain information about the transaction, fiscal receipt, issuer, and other related data.
Example XML Structure
The XML structure for Fiskalizacija 2.0 might look like this (this is a simplified example):
C# Code to Generate the XML
Here is how you can generate this XML structure in C# using
XmlWriter:using System; using System.Xml; class Fiskalizacija { public static void Main() { // Initialize the XML writer using (XmlWriter writer = XmlWriter.Create("fiskalizacija.xml", new XmlWriterSettings { Indent = true })) { writer.WriteStartDocument(); // Write the root element writer.WriteStartElement("Fiskalizacija"); // Write element writer.WriteStartElement("Zaglavlje"); writer.WriteElementString("OIB", "12345678901"); // OIB of the issuer writer.WriteElementString("VrstaDokumenta", "1"); // Type of document (1 = Invoice) writer.WriteElementString("DatumVrijeme", "2023-11-06T12:34:56"); // Date and time writer.WriteElementString("JIR", "202311061234567890"); // Unique Invoice Reference number writer.WriteElementString("Oznaka", "Fiskalizacija"); // Fiscalization status writer.WriteEndElement(); // End // Write element writer.WriteStartElement("Stavke"); // Write first item writer.WriteStartElement("Stavka"); writer.WriteElementString("Naziv", "Product 1"); writer.WriteElementString("Cijena", "100.00"); writer.WriteElementString("Kolicina", "2"); writer.WriteElementString("Porez", "25.00"); writer.WriteElementString("Iznos", "200.00"); writer.WriteEndElement(); // End first // Write second item writer.WriteStartElement("Stavka"); writer.WriteElementString("Naziv", "Product 2"); writer.WriteElementString("Cijena", "150.00"); writer.WriteElementString("Kolicina", "1"); writer.WriteElementString("Porez", "25.00"); writer.WriteElementString("Iznos", "150.00"); writer.WriteEndElement(); // End second writer.WriteEndElement(); // End // Write the element for the digital signature writer.WriteElementString("Potpis", "123456789abcdefg=="); writer.WriteEndElement(); // End writer.WriteEndDocument(); } Console.WriteLine("XML document created successfully!"); } }Explanation:
XmlWriter is used to create and write XML elements.
The structure follows the basic Fiskalizacija XML template.
For simplicity, I hard-coded some values (like
OIB,DatumVrijeme, etc.), but you can replace those with dynamic values.The
Potpiselement is just a placeholder for the digital signature. In a real scenario, the signature would be generated using an electronic signature mechanism, typically involving private keys and cryptography.Output (XML file)
When you run the C# program, it will generate an XML file named
fiskalizacija.xmlwith the following content:Notes:
Digital Signature: The digital signature (
Potpis) must be created using cryptographic methods, typically involving private keys and secure certificate handling. This example just uses a placeholder.Fields and Validation: You may need to validate the XML structure against a schema, especially the unique document identifiers like
JIR. You can use libraries likeXsdValidationto ensure your XML adheres to the required format.