Code for parsing and creating files for requesting RUT & ROT tax deductions from Skatteverket (Swedish Tax Agency)
Written in C#/.NET.
The project defines models representing the file structures of the XML and JSON files.
These are the scenarios:
- Parsing and creating RUT & ROT Request files in XML that will be sent to Skatteverket.
- Parsing the JSON files containing the Decisions you have got from Skatteverket.
I could not find any library or sample code for handling the files, so I decided to write this as a reference project.
The files are usually being produced by accounting software, like Fortnox. But there are scenarios when you want to parse and generate them yourself.
This demonstrates how to use the library.
using var stream = File.OpenRead("Begaran.xaml");
var begaran = RotRutBegaran.Deserialize(stream);
var begaran = new BegaranFil();
using var stream = File.OpenWrite("Begaran.xaml");
RotRutBegaran.Serialize(stream, begaran);
To perform a nested validation of the models:
var begaran = new BegaranFil();
var validationResults = new List<ValidationResult>();
var valid = RotRutBegaran.Validate(begaran, validationResults);
The structure is defined in the schema that can be found in the <repository>/Files/Schemas/v6
folder.
Basically, both ROT and RUT requests share the same root structure (BegaranFil),
ROT or RUT may only contain a maximum of 100 request posts per file (Ärende, "errand" or "matter"). Any number above needs to be put in a separate file.
These are some concepts that are being used in the code:
- Begäran - Request (for Skatteverket)
- Beslut - Decision (by Skatteverket)
- Polish the model
- Add validation to models
This code is being published with no warranty whatsoever.
The project should be considered a reference for your own implementation.
All personal numbers (SSN) have been generated for demo purposes.