Re: When Deserializing and object into a class, thereafter how do you delete a node?
- From: "Mitch Denny" <mitch.denny@xxxxxxxxxxxxxx>
- Date: Fri, 5 Aug 2005 22:14:36 +1000
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;
>
> }
>
>
>
.
- Prev by Date: Re: HELP:: ThreadPool.QueueUserWorkItem
- Next by Date: Re: calling a COM function
- Previous by thread: Re: HELP:: ThreadPool.QueueUserWorkItem
- Next by thread: Re: IErrorInfo in .NET
- Index(es):
Relevant Pages
|