I have an XML file containing 4 different strings, but I am having trouble deserializing the file. Could someone help me with this?
I looked online for answers, but none of them worked, I’m not sure what to do about it.
Here is the XML file I am trying to deserialize:
<?xml version="1.0" encoding="utf-8"?>
<saveData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<strFolder1>1st Location</strFolder1>
<strFolder2>2nd Location</strFolder2>
<strTabName>newTab0</strTabName>
<strTabText>Main</strTabText>
</saveData>
I’d recommend looking at XmlReader. Some other approaches are easier in different ways, but you can build anything from XmlReader. Such as:
(We could take some short-cuts if guaranteed the ordering, I did it the hard way to show that the hard way isn’t that hard).
Using XmlDocument, XmlSerializer and XDocument are easier in a lot of cases, but I recommend learning this first because it’ll handle everything and is never less efficient. If you learn it first the worse that’ll happen is you do a bit more work than necessary to end up with something a bit more efficient than strictly necessary (you’ll do a micro-optimisation out of ignorance of the simpler ways). If you learn the others first the worse that’ll happen is you do a lot more work than necessary to end up with something a lot less efficient than needed.