Hi there,
I've been searching the posts in this group and haven't been able to
find anything that suitably solves my problem.. anyway...
I am attempting to deserialize a class which I do not own, but the XML
generated can potentially be HUGE (as in, gigabytes), so I do not want
to deserialize all of it at once.
Anyway, here's an approximation of the class interfaces (that I cannot
change)
---------------------------
class BigStuff {
ControlInfo Control;
string Name;
string Path;
string OtherStuff;
Data TheData;
}
class ControlInfo {
.... //not relevant
}
class Data
ArrayList Items; //an arraylist containing DataItem objects
string Other;
}
class DataItem {
string Name;
string Type;
string BigData;
}
-------------------
Essentially, the BigData element in DataItem contains the huge amount
of data, and will just gobble up memory on a server if I try to
serialize it all at once. As a result, I want to get the control
information (and other stuff) in BigStuff, but I don't need to get
TheData right away. I will later use a forward only reader to get what
I need an work with it iteratively.
Here's the code I'm using to do the initial deserialization (during
which I want to skip the DataItem elements) - this I do have control
over:
-----------------------
XmlAttributeOverrides attrOverrides = new XmlAttributeOverrides();
if(true)
{
attrOverrides = new XmlAttributeOverrides();
XmlAttributes attrs = new XmlAttributes();
XmlElementAttribute attr = new XmlElementAttribute("Data");
attrs.XmlElements.Add(attr);
attrs.XmlIgnore = true;
attrOverrides.Add(typeof(BigStuff), "BigStuff", attrs);
}
XmlSerializer serializer = new XmlSerializer(typeof(BigStuff),
attrOverrides);
BigStuff stuff;
using(FileStream fs = new FileStream(fileLocation, FileMode.Open))
{
stuff = (BigStuff) serializer.Deserialize(fs);
fs.Close();
}
--------------------
The above code doesn't work - I always get the ArrayList of DataItem
elements no matter what I do... if anyone has any suggestions on how to
do this (I thought XmlAttributeOverrides and XmlIgnore were the way to
do this), please let me know!!
Thanks,
Ryan