473,503 Members | 2,075 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ignoring specific elements when Deserializing xml to an object

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

Nov 15 '05 #1
0 1085

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1834
by: Thomas | last post by:
Hi, I implemented a composite pattern which should be serializable to xml. After spending some time in the newsgroups, i finally managed serializing, even with utf-8 instead of utf-16, which...
1
1672
by: Jay | last post by:
Hello all. When using the XmlSerializer, you can create a property/field that tells the serializer whether or not to bother putting an element in the document. For example: // C# example....
0
1482
by: JMD | last post by:
I have a set of schemas for two different XML files that share common structures through the use of "import". Eventually, the main XSD file (which just gathers pieces from the common stuff to...
5
3144
by: Daniel Gackle | last post by:
I'm getting a strange ArgumentNullException after deserializing a SortedList. Haven't seen this discussed in the newsgroups, but it looks like a bug - unless I missed something obvious? I've...
2
3739
by: Phillip Galey | last post by:
I have an object called Place which contains only string properties and has the <Serializable()> flag before the class name declaration. I also have a collection object called Places, which is...
0
1059
by: Shane Story | last post by:
My other thread on serialization seemed to be stagnant and I still have questions, so I decided to post this example of what I need to know. I am trying to use binaryformatter. I have no trouble...
7
2161
by: Jason | last post by:
I have some XML that contains some null elements, for example: <Document> <StartDate/> <EndDate/> </Document> I would like to process the XML using the .NET serialization tools (XSD.exe). ...
1
11759
by: =?Utf-8?B?SmVyZW15X0I=?= | last post by:
I am working on an order entry program and have a question related to deserializing nodes with nested elements. The purchase order contains multiple line items which I select using an...
0
2786
by: theonlydavewilliams | last post by:
Hi there I'm hoping there's an easy answer to a (hopefully) not too long-winded issue... I'm building a C# web client using a proxy wsdl.exe'd from a wsdl file and six schemas, each in a different...
0
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5562
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.