This has been killing me for the whole of today.
I’ve just recently introduced myself to XML and I’m trying to use an XML database to store parts of customizable boats.
<moduledatabase>
<HullConfig>
<name = "Small Hull">
<modulecost> 10 </modulecost>
<effect> 1 </effect>
</name>
<name = "Medium Hull">
<modulecost> 15 </modulecost>
<effect> 1.5 </effect>
</name>
</HullConfig>
</moduledatabase>
Ideally this database wouldn’t just contain hull sections, but also any other customizable sections, I.e. , and pull lists of the different potential configurations when a player is browsing them.
Unfortunately every tutorial I’ve come across involving pulling multiple items from the database only touches on pulling items of a single ‘category’ (array), and tells me to do it like so:
[XmlRoot("moduledatabase")]
public class ModulePuller {
[XmlArray("HullConfig")]
[XmlArrayItem("name")]
public List<Module> modules = new List<Module>();
}
While this works perfectly for pulling a list of all hull configurations, it’s apparently impossible to selectively alter the XMLArray variables as they are static (it throws CS0120) - so if/when I add more categories of modules (such as an ) I’m unable to tell the XmlArray/deserializer to change the category of items it’s meant to pull.
The only feasible workaround that I can see is making lots of different XML files for each type of module I want to add, with respective classes, which just seems unnecessary and tedious.
Sorry if there’s a simple workaround that I can’t see, or if this is the only way and I’m being lazy. But is there a way to specify certain brackets to get their content as described?