Re: When Deserializing and object into a class, thereafter how do you delete a node?

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi Mark,

Because its an array you would need to do some array gymnastics. It may
actually be easier to load it into an ArrayList and do it that way, but here
is some (untested) code anyway.

books booksInstance = // Get your books instance.
booksBook subset = new booksBook[booksInstance.Items.Length - 1];
Array.Copy(booksInstance.Items, 0, subset, 0, 1);
Array.Copy(booksInstance.Items, 2, subset, 1, booksInstance.items.Length -
1];
booksInstance.Items = subset;


--



Mitch Denny
email: mitch.denny@xxxxxxxxxxxxxx
mobile: +61 (414) 610-141
blog: http://notgartner.com
skype: callto://mitchdenny


"Mark Rance" <nomail@xxxxxxxxxxxx> wrote in message
news:dqqdncy-Xsep7R7fRVn-vQ@xxxxxxxxxxxxx
> Using the example XML file below, I created via the xsd tool, a class so
> as
> to be able to serialize/deserialize the data. The generated class, as per
> usual, has an Items collection of booksBook objects. So once I
> deserialize
> into the class from the file, populating the Items collection...how do I
> then delete 1 or more of the items in the collection? And then, of
> course,
> I want to Serialize again to change the on disk file contents.
>
> // Sample Xml File
> <?xml version="1.0" encoding="UTF-8"?>
> <books>
> <book>
> <title>For Whom The Bell Tolls</title>
> <author>Bob Straub></author>
> </book>
> <book>
> <title>It Takes a Village</title>
> <author>First Lady</author>
> </book>
> </books>
>
> // Generated class
>
>
> //
> // This source code was auto-generated by xsd, Version=1.1.4322.2032.
> //
>
> using System.Xml.Serialization;
>
> [System.Xml.Serialization.XmlRootAttribute(Namespace="",
> IsNullable=false)]
>
> public class books
> {
> [System.Xml.Serialization.XmlElementAttribute("book",
> Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
> public booksBook[] Items;
> }
>
> public class booksBook
> {
>
> [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSche
> maForm.Unqualified)]
> public string title;
>
>
> [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSche
> maForm.Unqualified)]
> public string author;
>
> }
>
>
>


.



Relevant Pages

  • Re: Exteding the AdRotator Control and Advert.xml file to track advert stats
    ... The code below is my current solution to creating a Tracked adRotator, I hope you can agree that it is a very compact solution. ... public class Redirector: IHttpHandler ... XML file is a "Database" of sorts, I was trying to avoid the overheads of another database in my site. ... The simplicity of this solution was what interested me as I already have a sophisitcated XML file handling utility class which has meant that I only needed to add 4 lines of code to an overriden usercontrol to impliment the majority of the functionality. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Deserialize - Casting error
    ... and it deserializes ok, but get an error on the cast, still. ... I then embedded the .xml file, and read from the assembly, just to make ... public class CustomClass ...
    (microsoft.public.dotnet.xml)
  • Re: NonSerialized
    ... > I'm using XmlSerializer and TextWriter classes to create xml file ... > public class x ... XmlSerializer uses IXmlSerializable as interface. ... the new O/R mapper for .NET: http://www.llblgen.com My .NET Blog: http://weblogs.asp.net/fbouma Microsoft C# MVP ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Where does MCE2k5 store its saved tv guide?
    ... public void activate(string deviceType, string activationKey) ... public class HttpWebResponseDecompressed: System.Net.WebResponse ... DataDirectListings List = new DataDirectListings; ... XML file that is saved to your local hard drive containing the data that was ...
    (microsoft.public.windows.mediacenter)