UBL XML Creation in .NET
UBL (Universal Business Language) XML is a structured xml is very important in zatca implementation in KSA.
Here is the tutorial for generating UBL XML in Asp.Net c#.
Create a project in c# application. Here I created console application in .NET 7.0
then add class 'Invoice.cs'
then open sample invoice format (eg: StandardInvoice.xml that is provided by zatca in their sdk tool)
(or download sample file here
copy the the whole content in sample xml. then move to Invoice class that we created
then go to edit -> paste special -> Paste XML as Classes
next we have to code on 'program.cs' file
Invoice obj = new Invoice();
obj.ID = new ID
{
Value = "SME00023"
};
obj.UUID = "8d487816-70b8-4ade-a618-9d620b73814a";
obj.IssueDate = DateTime.Now;
XmlSerializer serializer = new XmlSerializer(typeof(Invoice));
var myNameSpace = new XmlSerializerNamespaces();
myNameSpace.Add("cbc", "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2");
myNameSpace.Add("cac", "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2");
using (TextWriter textWriter = new StreamWriter("ublXmlSample.xml"))
{
serializer.Serialize(textWriter, obj, myNameSpace);
}
Console.WriteLine("xml created");
insert code on main method on 'program.cs' class (show below)
Here added only three tags. you can use all properties in invoice class. then run the code.
'ublxmlsample.xml' file will generate on debug folder.
Comments
Post a Comment