I'm working on getting my .net object serialized\deserialized. As a requirement for our XML files, the object must be inside a master node named "MyCompany", here is an example for the file:
<?xml version="1.0" encoding="utf-8"?>
<mycompany>
<station>
<serial>VAA008090067</serial>
</station>
</mycompany>
I'm running into an issue getting this to DeSerialize. I'm not aware of how to tell the Serializer "Hey, make sure you dig into the MyCompany node before you serialize." Here is my current DeSerializtion code (not accounting for a root node).
Stream binaryStream = File.Open(Filename, FileMode.Open);
XmlSerializer xformatter = xformatter = new XmlSerializer(typeof(T));
obj = (T)xformatter->Deserialize(stream);
I attempted to do the following code: Create a XmlTextStream, read in the file header node, and the company node, then pass the stream to the serializer
Stream binaryStream = File.Open(Filename, FileMode.Open);
xmlReader = gcnew XmlTextReader(binaryStream);
xmlReader.Read(); //add error checking
xmlReader.Read(); //add error checking
xformatter = gcnew XmlSerializer(T.typeid);
obj = (T)xformatter.Deserialize(xmlReader);
The above doesn't work, throws me a "XmlElement Error: Root Element is missing"
I know there is a simple solution, but I am unable to find it.
Thanks in advance