Parsing XML directly into serializable object?
I wrote a snippet of code to handle parsing an XML document into an
IAsyncEnumerable
of objects containing all of the necessary xml attributes/element data I want to capture, but was reading a bit about some better techniques for this type of thing and noticed some stackoverflow posts mentioning a method that's possible by using a type that's tagged with Serializable
. The only issue is that I can't seem to find examples of how to do this.
Is there an simple modification to this code here to be able to deserialize an XElement
directly into a Compound
object? The code is already starting to get messy and am hoping there's something I can use to either infer the schema of the XML document, then use that to serialize... or if possible just serialize into the object directly.
This is the code I'd like to simplify with this type of an approach if possible:
https://github.com/vorlac/cppreference-docs-vs-extension/blob/main/DocumentationProcessor/Core/Indexer.cs#L51-L145
And this is the XML doc being parsed:
https://gist.github.com/vorlac/0514ed1920eb69d00e00af7631c1a528
Any help with the syntax needed to handle that conversion would be appreciated (or alternative parsing approaches altogether). The plan is to parse out as much info as possible, then store the data in a sqlite database, so if there are any shortcuts to pull that off (i.e. something that would allow a direct XML => sqlite transform).0 Replies