C
C#

help

✅ XML Serialization

FFroH.LVT2/1/2023
I want to customize XML serialization. This is sample class
public class Sample{
public List<TestCategory> TestList {get;set;}
}

public class TestCategory{
public string Value {get;set;} = "Random string";
}
public class Sample{
public List<TestCategory> TestList {get;set;}
}

public class TestCategory{
public string Value {get;set;} = "Random string";
}
FFroH.LVT2/1/2023
this is current result
FFroH.LVT2/1/2023
But i want something like this:
FFroH.LVT2/1/2023
It's my first time to do stuff with XML, quite new to this. What can I do to achieve my target? Thank you Here is serialization code :
var item = new Sample();
item.TestList = new List<Category>(){new TestCategory(),new TestCategory(),new TestCategory(),new TestCategory(),};
string fileName = "";
XmlSerializer x = new XmlSerializer(typeof(Sample));
TextWriter writer = new StreamWriter(fileName);
x.Serialize(writer, item);
var item = new Sample();
item.TestList = new List<Category>(){new TestCategory(),new TestCategory(),new TestCategory(),new TestCategory(),};
string fileName = "";
XmlSerializer x = new XmlSerializer(typeof(Sample));
TextWriter writer = new StreamWriter(fileName);
x.Serialize(writer, item);
PPobiega2/1/2023
The simplest way would be to have a model that more accurately reflects the desired XML structure. You could map your original data into this new structure before serialization or after deserialization.
FFroH.LVT2/1/2023
Yes, i'm trying to do that this is what I have to make https://stackoverflow.com/questions/5112505/xml-string-array-deserialize-as-different-type-name ah I found this !answer

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
❔ ✅ Can't find System.Data.Entity to build a dbContext after installing the EntityFrameWork PackageFor a project I'm working on I need to be using the entity framework to add migrations to a postgres❔ How can I handle error❔ Non-nullable field 'rating' must contain a non-null value when exiting constructorWhy am i getting this warning: `Non-nullable field 'rating' must contain a non-null value when exiti❔ How can I dock a form inside of a TabPage?How can I dock a form inside of a TabPage in C#?✅ Object reference error? Using UnityI'm trying to create a slider system to visualize various status bars using references instead of di❔ Display string that divided 1 by 1 word in textbox.I tried to display string sentence 1 by 1 word in textbox. I used string.split() method to split. Bu❔ Will there be issues if the target framework moniker is less than my .NET version installed?Total scrub here, please correct if I say anything wrong. I've got Visual Studio installed with .NET❔ Singleton Pattern StackOverflowExceptionIn the attached code, the GameManager is working fine, but InputManager is throwing a StackOverflowEGet the first letters of a stringHello, Let's say that I have the string "tyranitar". With string[X], I can get the letter that I wa❔ I cant find the Option "ConsoleApp" when creating a new projektI also installed the .NET thing but i cant choose it, one screenshot is from a tut and other one sho❔ hello, Im new in C# codding, could someone help me ? I think something is wrong in my code :(Restoring my source codeHello, I have built a simple C# app, and i debugged it and only got the .config, .exe and .pdb files❔ Callback Url Always NullHere's the two functions involved ``` public IActionResult ExternalLogin(string provider, str❔ Game telemetry & overlay project - help with framework & architecture decisionstl;dr I want to create an application which continuously reads telemetry data from a racing game anderror CS0176: Member 'DateTime.Now' cannot be accessed with an instance reference; qualify it with aHi, i'm a beginner and i come from JavaScript and python. I'm having an issue with my CSharp code: `❔ Dapper - Call stored procedure errorI finished to write my first POST Api, but I get an error when I execute it and it call a stored pro❔ Is it real to use a aspnet identity without the IdentityUser?I want to add accounts to my website, but I don't need all fields of the ``IdentityUser``. Is there ❔ How to publish multiple projects under one solution?I created ASP.Net Core API project, 4 library projects and a few unit test projects - all under one ❔ Models for JSON from APIIn Tim Coreys video he had an API with this sort of JSON structure: `results: sunrise: "valu❔ [Error] The added or subtracted value results in an un-representable DateTime.I have following function: ``` private static void BuildPeriodTable( WorktimeDataSet stds, DateTime