473,654 Members | 3,114 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:
-----------------------
XmlAttributeOve rrides attrOverrides = new XmlAttributeOve rrides();
if(true)
{
attrOverrides = new XmlAttributeOve rrides();
XmlAttributes attrs = new XmlAttributes() ;
XmlElementAttri bute attr = new XmlElementAttri bute("Data");
attrs.XmlElemen ts.Add(attr);
attrs.XmlIgnore = true;
attrOverrides.A dd(typeof(BigSt uff), "BigStuff", attrs);
}
XmlSerializer serializer = new XmlSerializer(t ypeof(BigStuff) ,
attrOverrides);

BigStuff stuff;

using(FileStrea m fs = new FileStream(file Location, FileMode.Open))
{
stuff = (BigStuff) serializer.Dese rialize(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 XmlAttributeOve rrides and XmlIgnore were the way to
do this), please let me know!!

Thanks,

Ryan

Nov 15 '05 #1
0 1090

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

Similar topics

1
1850
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 causes ie problems. But when deserializing the xml into the object structure, the following exception is beeing thrown: There is an error in XML document (3, 701).
1
1681
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. public class MyClass { public bool MyPropSpecified; public int MyProp;
0
1487
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 show what goes in this root element) contains: <xs:element name= "ImageBox" type="ns:ImageBox_t" form="qualified" /> I use a validating reader to pull this into an XmlDocument. Then, step
5
3154
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 distilled the problem into the following code. Can anybody reproduce/explain the problem? Thanks, Daniel
2
3758
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 implemented using Inherits System.Collections.Specialized.NameObjectCollectionBase and also has the <Serializable()> flag before the class name declaration. In the calling code, I'm successfully serializing the object to an XML file using a...
0
1061
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 saving (serializing), but when I go to deserialize I always get errors. It appears that I cannot set a breakpoint or anything to discover where the problem is. I am serializing by implementing ISerializable: The GetObjectData method and the...
7
2169
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). The schema for the XML is under external control (i.e. I can't change it).
1
11780
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 XmlNodeList. I am trying to deserialize the nodes using a foreach as follows: foreach(XmlNode lineItem in LineItemsNodeList) An abbreviated example of the nested lineItem node looks like this:
0
2796
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 namespace. Some schemas extend complex types in others. When i get a soap:Fault from my test server it could contain a serialized exception object (called fault) from one of two of these schemas (and different namespaces, call them xmlns:b0="ns1" and...
0
8294
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8709
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8494
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6162
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5627
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1924
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1597
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.