473,942 Members | 14,380 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlSerializer Collection with Collections

Hello I got this working but it is not how I really want it, basically
I have an xml file which has a root of <test> and can be filled with 3
different types of <question> elements with different attributes, all
share a base set of 4, one of the question types can have children
with <option> elements, this is how the xml looks after
serialization.. ..

If you notice there is an extra <SelectionLis t> around the <option>'s
in the
final <question>, how can I write my class so I don't have this extra
<SelectionLis t> element....my class follows, you can see in the 2nd
public Question constructor is where I add the OptionList type....any
ideas, I know that really there is nothing wrong with having an extra
<SelectionLis t> element around the <option> elements but I really want
to know if my class is properly constucted.
<?xml version="1.0" encoding="utf-8"?>
<Test xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance">
<Question text="What is love?" type="Input" score="3"
mandatory="fals e" multiLine="fals e" maxlength="0" minlength="0"
validate="None" />
<Question text="This is better than sliced bread?" type="Input"
score="9" mandatory="fals e" multiLine="fals e" maxlength="0"
minlength="0" validate="None" />
<Question text="input question" type="Input" score="8"
mandatory="true " multiLine="true " maxlength="7" minlength="1"
initialvalue="h ello" validate="Curre ncy" answer="this is the answer"
/>
<Question text="What is square root of 2?" type="selection "
score="3" mandatory="fals e" multiLine="fals e" maxlength="0"
minlength="0" validate="None" >
<SelectionLis t>
<Option text="first" selected="true" tooltip="hovert ext"
answer="false" />
<Option text="second" selected="true" tooltip="hovert ext"
answer="true" />
</SelectionList>
</Question>
</Test>

using System;
using System.Collecti ons;
using System.IO;
using System.Xml;
using System.Xml.Seri alization;

namespace TestCreator
{
public class TestSerializer
{
public TestSerializer( )
{
//
// TODO: Add constructor logic here
//
}

//test class which will be serialized
[XmlRoot("Test")]
public class QuestionList
{
private ArrayList listQuestions;

public QuestionList()
{
listQuestions = new ArrayList();
}

[XmlElement("Que stion")]
public Question[] Questions
{
get
{
Question[] questions = new Question[ listQuestions.C ount ];
listQuestions.C opyTo( questions );
return questions;
}
set
{
if( value == null ) return;
Question[] questions = (Question[])value;
listQuestions.C lear();
foreach( Question question in questions )
listQuestions.A dd( question );
}
}

public int AddQuestion( Question question )
{
return listQuestions.A dd( question );
}
}

public class OptionList
{
private ArrayList listOptions;

public OptionList()
{
listOptions = new ArrayList();
}
[XmlElement("Opt ion")]
public Option[] Options
{
get
{
Option[] options = new Option[ listOptions.Cou nt ];
listOptions.Cop yTo( options );
return options;
}
set
{
if( value == null ) return;
Option[] options = (Option[])value;
listOptions.Cle ar();
foreach( Option option in options )
listOptions.Add ( option );
}
}
public int AddOption( Option option )
{
return listOptions.Add ( option );
}
}

public class Question
{
[XmlAttribute("t ext")] public string questionText;
[XmlAttribute("t ype")] public string type;
[XmlAttribute("s core")] public int score;
[XmlAttribute("m andatory")] public bool mandatory;
[XmlAttribute("m ultiLine")] public bool multiline;
[XmlAttribute("m axlength")] public int maxlength;
[XmlAttribute("m inlength")] public int minlength;
[XmlAttribute("i nitialvalue")] public string initialvalue;
[XmlAttribute("v alidate")] public Validation validate;
[XmlAttribute("a nswer")] public string answer;
[XmlElement("Sel ectionList")] public OptionList optionlist;
//[XmlElement("go" )] public ArrayList optionlist;

public enum Validation
{
None,
Date,
Integer,
Currency
}
public Question()
{
}

public Question( string QuestionText, string Type, int Score, bool
Mandatory, OptionList opl )
{
questionText = QuestionText;
type = Type;
score = Score;
mandatory = Mandatory;
optionlist = opl;
}

public Question( string QuestionText, string Type, int Score, bool
Mandatory, bool MultiLine, int MaxLength, int MinLength, string
InitialValue, Validation Validate, string Answer)
{
questionText = QuestionText;
type = Type;
score = Score;
mandatory = Mandatory;
multiline = MultiLine;
maxlength = MaxLength;
minlength = MinLength;
initialvalue = InitialValue;
validate = Validate;
answer = Answer;
}
}

public class Option
{
[XmlAttribute("t ext")] public string label;
[XmlAttribute("s elected")] public bool selected;
[XmlAttribute("t ooltip")] public string tooltip;
[XmlAttribute("a nswer")] public bool answer;

public Option()
{
}

public Option( string Label, bool Selected, string Tooltip, bool
Answer )
{
label = Label;
selected = Selected;
tooltip = Tooltip;
answer = Answer;
}
}

public static void Serialize(Quest ionList myList)
{
XmlSerializer s = new XmlSerializer( typeof( QuestionList ) );
TextWriter w = new StreamWriter( @"c:\list.xm l" );
s.Serialize( w, myList );
w.Close();
}
}
}

To test do this:
TestSerializer. QuestionList myList = new
TestSerializer. QuestionList();
myList.AddQuest ion( new TestSerializer. Question("What is
love?","Input", 3,false ) );

TestSerializer. OptionList opl = new TestSerializer. OptionList();
opl.AddOption( new TestSerializer. Option("first", true,"hovertext ",false));
opl.AddOption( new TestSerializer. Option("second" ,true,"hovertex t",true));
myList.AddQuest ion( new TestSerializer. Question("What is the square
root of 2?","selection" ,3,false,opl ) );
TestSerializer. Serialize(myLis t);
Nov 12 '05 #1
3 4249
> I really want
to know if my class is properly constucted.
your class is fine.

But it is possible to shape the XML differently. For example, if you change
from this:
[XmlElement("Sel ectionList")] public OptionList optionlist;

to this:
[XmlElement("Opt ion", typeof(Option))]
public ArrayList options;

you will get this:
<Test>
<Question .../>
<Question ...>
<Option .../>
<Option .../>
</Question>
</Test>

But you will lose the type-enforcement provided by OptionList. Another
way to do it is to embed the Option[] in the Question type directly,
instead of going through the intermediary type OptionList. So, move the
following snippet from OptionList directly into Question:

--- begin snip ----
private ArrayList listOptions= new ArrayList();

[XmlElement("Opt ion")]
public Option[] Options
{
get {..}
set {...}
}
public int AddOption( Option option )
{
return listOptions.Add ( option );
}
--- end snip ----

This retains the type enforcement you have now, and will get you the simpler
XML you described. In fact this approach seems more parallel with your
existing design for QuestionList. Put aside the names for a moment and
think about it. Instead of QuestionList, let's call it QuestionSet. In
the current design,

- a bunch of Question objects are contained within a QuestionSet
- a bunch of Option objects are contained within an OptionList
- a single OptionList object is contained within a Question

Whereas in the modified version,

- a bunch of Question objects are contained within a QuestionSet
- a bunch of Option objects are contained within a Question.

It is the extra level of object containment in the original version that
gets you the extra level of XML hierarchy.
-Dino
"MattB" <MB*********@ya hoo.co.uk> wrote in message
news:b4******** *************** **@posting.goog le.com... Hello I got this working but it is not how I really want it, basically
I have an xml file which has a root of <test> and can be filled with 3
different types of <question> elements with different attributes, all
share a base set of 4, one of the question types can have children
with <option> elements, this is how the xml looks after
serialization.. ..

If you notice there is an extra <SelectionLis t> around the <option>'s
in the
final <question>, how can I write my class so I don't have this extra
<SelectionLis t> element....my class follows, you can see in the 2nd
public Question constructor is where I add the OptionList type....any
ideas, I know that really there is nothing wrong with having an extra
<SelectionLis t> element around the <option> elements but I really want
to know if my class is properly constucted.
<?xml version="1.0" encoding="utf-8"?>
<Test xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance">
<Question text="What is love?" type="Input" score="3"
mandatory="fals e" multiLine="fals e" maxlength="0" minlength="0"
validate="None" />
<Question text="This is better than sliced bread?" type="Input"
score="9" mandatory="fals e" multiLine="fals e" maxlength="0"
minlength="0" validate="None" />
<Question text="input question" type="Input" score="8"
mandatory="true " multiLine="true " maxlength="7" minlength="1"
initialvalue="h ello" validate="Curre ncy" answer="this is the answer"
/>
<Question text="What is square root of 2?" type="selection "
score="3" mandatory="fals e" multiLine="fals e" maxlength="0"
minlength="0" validate="None" >
<SelectionLis t>
<Option text="first" selected="true" tooltip="hovert ext"
answer="false" />
<Option text="second" selected="true" tooltip="hovert ext"
answer="true" />
</SelectionList>
</Question>
</Test>

using System;
using System.Collecti ons;
using System.IO;
using System.Xml;
using System.Xml.Seri alization;

namespace TestCreator
{
public class TestSerializer
{
public TestSerializer( )
{
//
// TODO: Add constructor logic here
//
}

//test class which will be serialized
[XmlRoot("Test")]
public class QuestionList
{
private ArrayList listQuestions;

public QuestionList()
{
listQuestions = new ArrayList();
}

[XmlElement("Que stion")]
public Question[] Questions
{
get
{
Question[] questions = new Question[ listQuestions.C ount ];
listQuestions.C opyTo( questions );
return questions;
}
set
{
if( value == null ) return;
Question[] questions = (Question[])value;
listQuestions.C lear();
foreach( Question question in questions )
listQuestions.A dd( question );
}
}

public int AddQuestion( Question question )
{
return listQuestions.A dd( question );
}
}

public class OptionList
{
private ArrayList listOptions;

public OptionList()
{
listOptions = new ArrayList();
}
[XmlElement("Opt ion")]
public Option[] Options
{
get
{
Option[] options = new Option[ listOptions.Cou nt ];
listOptions.Cop yTo( options );
return options;
}
set
{
if( value == null ) return;
Option[] options = (Option[])value;
listOptions.Cle ar();
foreach( Option option in options )
listOptions.Add ( option );
}
}
public int AddOption( Option option )
{
return listOptions.Add ( option );
}
}

public class Question
{
[XmlAttribute("t ext")] public string questionText;
[XmlAttribute("t ype")] public string type;
[XmlAttribute("s core")] public int score;
[XmlAttribute("m andatory")] public bool mandatory;
[XmlAttribute("m ultiLine")] public bool multiline;
[XmlAttribute("m axlength")] public int maxlength;
[XmlAttribute("m inlength")] public int minlength;
[XmlAttribute("i nitialvalue")] public string initialvalue;
[XmlAttribute("v alidate")] public Validation validate;
[XmlAttribute("a nswer")] public string answer;
[XmlElement("Sel ectionList")] public OptionList optionlist;
//[XmlElement("go" )] public ArrayList optionlist;

public enum Validation
{
None,
Date,
Integer,
Currency
}
public Question()
{
}

public Question( string QuestionText, string Type, int Score, bool
Mandatory, OptionList opl )
{
questionText = QuestionText;
type = Type;
score = Score;
mandatory = Mandatory;
optionlist = opl;
}

public Question( string QuestionText, string Type, int Score, bool
Mandatory, bool MultiLine, int MaxLength, int MinLength, string
InitialValue, Validation Validate, string Answer)
{
questionText = QuestionText;
type = Type;
score = Score;
mandatory = Mandatory;
multiline = MultiLine;
maxlength = MaxLength;
minlength = MinLength;
initialvalue = InitialValue;
validate = Validate;
answer = Answer;
}
}

public class Option
{
[XmlAttribute("t ext")] public string label;
[XmlAttribute("s elected")] public bool selected;
[XmlAttribute("t ooltip")] public string tooltip;
[XmlAttribute("a nswer")] public bool answer;

public Option()
{
}

public Option( string Label, bool Selected, string Tooltip, bool
Answer )
{
label = Label;
selected = Selected;
tooltip = Tooltip;
answer = Answer;
}
}

public static void Serialize(Quest ionList myList)
{
XmlSerializer s = new XmlSerializer( typeof( QuestionList ) );
TextWriter w = new StreamWriter( @"c:\list.xm l" );
s.Serialize( w, myList );
w.Close();
}
}
}

To test do this:
TestSerializer. QuestionList myList = new
TestSerializer. QuestionList();
myList.AddQuest ion( new TestSerializer. Question("What is
love?","Input", 3,false ) );

TestSerializer. OptionList opl = new TestSerializer. OptionList();
opl.AddOption( new TestSerializer. Option("first", true,"hovertext ",false));
opl.AddOption( new TestSerializer. Option("second" ,true,"hovertex t",true));
myList.AddQuest ion( new TestSerializer. Question("What is the square
root of 2?","selection" ,3,false,opl ) );
TestSerializer. Serialize(myLis t);

Nov 12 '05 #2
Hi thanks for the reply,

As you said the first method did work but as you mentioned I lost
type-enforcement provided by OptionList, my calling code changed to
this...

<code>
QuestionList myList = new QuestionList();

myList.AddQuest ion( new Serialize.Quest ion("This is better than sliced
bread?","Input" ,9,false ) );

myList.AddQuest ion( new Serialize.Quest ion("input question","inpu t",
8, true, true, 7, 1, "hello", Serialize.Quest ion.Validation. Currency,
"this is the answer"));

ArrayList arl = new ArrayList();
arl.Add( new Serialize.Optio n("first",true, "hovertext",fal se) );
arl.Add( new Serialize.Optio n("second",true ,"hovertext",tr ue) );

myList.AddQuest ion( new Serialize.Quest ion("What is slayer of
conformity?","s election",3,fal se, arl ) );

Serialize.Write Xml(myList);
</code>

I then tried your 2nd solution and the calling code above still worked
but I also noticed I could add Options without them being part or
under
a Question....

Option o1 = new Option("first", true,"hovertext ",false);
myList.AddOptio n(o1);
Option o2 = new Option("second" ,true,"hovertex t",true);
myList.AddOptio n(o2);

The xml looking something like this....top node fragment is still
filling and adding an arraylist to the question, bottom nodes are
added with the AddOption
command.

<Question text="What is slayer of conformity?" type="selection "
score="3" mandatory="fals e" multiLine="fals e" maxlength="0"
minlength="0" validate="None" >
<Option text="first" selected="true" tooltip="hovert ext"
answer="false" />
<Option text="second" selected="true" tooltip="hovert ext"
answer="true" />
</Question>
<Option text="first" selected="true" tooltip="hovert ext"
answer="false" />
<Option text="second" selected="true" tooltip="hovert ext"
answer="true" />

Might there be a way to use addoption to add it to the current
question??

Perhaps I must fiddle with the methods, getter & setters, but I want
to know if you have any ideas or am I going in the right direction
here.

Thanks,
Matt

p.s. is .net version 2 changing xml serialization?

"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote in message news:<eK******* *******@TK2MSFT NGP09.phx.gbl>. ..
I really want
to know if my class is properly constucted.


your class is fine.

But it is possible to shape the XML differently. For example, if you change
from this:
[XmlElement("Sel ectionList")] public OptionList optionlist;

to this:
[XmlElement("Opt ion", typeof(Option))]
public ArrayList options;

you will get this:
<Test>
<Question .../>
<Question ...>
<Option .../>
<Option .../>
</Question>
</Test>

But you will lose the type-enforcement provided by OptionList. Another
way to do it is to embed the Option[] in the Question type directly,
instead of going through the intermediary type OptionList. So, move the
following snippet from OptionList directly into Question:

--- begin snip ----
private ArrayList listOptions= new ArrayList();

[XmlElement("Opt ion")]
public Option[] Options
{
get {..}
set {...}
}
public int AddOption( Option option )
{
return listOptions.Add ( option );
}
--- end snip ----

This retains the type enforcement you have now, and will get you the simpler
XML you described. In fact this approach seems more parallel with your
existing design for QuestionList. Put aside the names for a moment and
think about it. Instead of QuestionList, let's call it QuestionSet. In
the current design,

- a bunch of Question objects are contained within a QuestionSet
- a bunch of Option objects are contained within an OptionList
- a single OptionList object is contained within a Question

Whereas in the modified version,

- a bunch of Question objects are contained within a QuestionSet
- a bunch of Option objects are contained within a Question.

It is the extra level of object containment in the original version that
gets you the extra level of XML hierarchy.
-Dino
"MattB" <MB*********@ya hoo.co.uk> wrote in message
news:b4******** *************** **@posting.goog le.com...
Hello I got this working but it is not how I really want it, basically
I have an xml file which has a root of <test> and can be filled with 3
different types of <question> elements with different attributes, all
share a base set of 4, one of the question types can have children
with <option> elements, this is how the xml looks after
serialization.. ..

If you notice there is an extra <SelectionLis t> around the <option>'s
in the
final <question>, how can I write my class so I don't have this extra
<SelectionLis t> element....my class follows, you can see in the 2nd
public Question constructor is where I add the OptionList type....any
ideas, I know that really there is nothing wrong with having an extra
<SelectionLis t> element around the <option> elements but I really want
to know if my class is properly constucted.
<?xml version="1.0" encoding="utf-8"?>
<Test xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance">
<Question text="What is love?" type="Input" score="3"
mandatory="fals e" multiLine="fals e" maxlength="0" minlength="0"
validate="None" />
<Question text="This is better than sliced bread?" type="Input"
score="9" mandatory="fals e" multiLine="fals e" maxlength="0"
minlength="0" validate="None" />
<Question text="input question" type="Input" score="8"
mandatory="true " multiLine="true " maxlength="7" minlength="1"
initialvalue="h ello" validate="Curre ncy" answer="this is the answer"
/>
<Question text="What is square root of 2?" type="selection "
score="3" mandatory="fals e" multiLine="fals e" maxlength="0"
minlength="0" validate="None" >
<SelectionLis t>
<Option text="first" selected="true" tooltip="hovert ext"
answer="false" />
<Option text="second" selected="true" tooltip="hovert ext"
answer="true" />
</SelectionList>
</Question>
</Test>

using System;
using System.Collecti ons;
using System.IO;
using System.Xml;
using System.Xml.Seri alization;

namespace TestCreator
{
public class TestSerializer
{
public TestSerializer( )
{
//
// TODO: Add constructor logic here
//
}

//test class which will be serialized
[XmlRoot("Test")]
public class QuestionList
{
private ArrayList listQuestions;

public QuestionList()
{
listQuestions = new ArrayList();
}

[XmlElement("Que stion")]
public Question[] Questions
{
get
{
Question[] questions = new Question[ listQuestions.C ount ];
listQuestions.C opyTo( questions );
return questions;
}
set
{
if( value == null ) return;
Question[] questions = (Question[])value;
listQuestions.C lear();
foreach( Question question in questions )
listQuestions.A dd( question );
}
}

public int AddQuestion( Question question )
{
return listQuestions.A dd( question );
}
}

public class OptionList
{
private ArrayList listOptions;

public OptionList()
{
listOptions = new ArrayList();
}
[XmlElement("Opt ion")]
public Option[] Options
{
get
{
Option[] options = new Option[ listOptions.Cou nt ];
listOptions.Cop yTo( options );
return options;
}
set
{
if( value == null ) return;
Option[] options = (Option[])value;
listOptions.Cle ar();
foreach( Option option in options )
listOptions.Add ( option );
}
}
public int AddOption( Option option )
{
return listOptions.Add ( option );
}
}

public class Question
{
[XmlAttribute("t ext")] public string questionText;
[XmlAttribute("t ype")] public string type;
[XmlAttribute("s core")] public int score;
[XmlAttribute("m andatory")] public bool mandatory;
[XmlAttribute("m ultiLine")] public bool multiline;
[XmlAttribute("m axlength")] public int maxlength;
[XmlAttribute("m inlength")] public int minlength;
[XmlAttribute("i nitialvalue")] public string initialvalue;
[XmlAttribute("v alidate")] public Validation validate;
[XmlAttribute("a nswer")] public string answer;
[XmlElement("Sel ectionList")] public OptionList optionlist;
//[XmlElement("go" )] public ArrayList optionlist;

public enum Validation
{
None,
Date,
Integer,
Currency
}
public Question()
{
}

public Question( string QuestionText, string Type, int Score, bool
Mandatory, OptionList opl )
{
questionText = QuestionText;
type = Type;
score = Score;
mandatory = Mandatory;
optionlist = opl;
}

public Question( string QuestionText, string Type, int Score, bool
Mandatory, bool MultiLine, int MaxLength, int MinLength, string
InitialValue, Validation Validate, string Answer)
{
questionText = QuestionText;
type = Type;
score = Score;
mandatory = Mandatory;
multiline = MultiLine;
maxlength = MaxLength;
minlength = MinLength;
initialvalue = InitialValue;
validate = Validate;
answer = Answer;
}
}

public class Option
{
[XmlAttribute("t ext")] public string label;
[XmlAttribute("s elected")] public bool selected;
[XmlAttribute("t ooltip")] public string tooltip;
[XmlAttribute("a nswer")] public bool answer;

public Option()
{
}

public Option( string Label, bool Selected, string Tooltip, bool
Answer )
{
label = Label;
selected = Selected;
tooltip = Tooltip;
answer = Answer;
}
}

public static void Serialize(Quest ionList myList)
{
XmlSerializer s = new XmlSerializer( typeof( QuestionList ) );
TextWriter w = new StreamWriter( @"c:\list.xm l" );
s.Serialize( w, myList );
w.Close();
}
}
}

To test do this:
TestSerializer. QuestionList myList = new
TestSerializer. QuestionList();
myList.AddQuest ion( new TestSerializer. Question("What is
love?","Input", 3,false ) );

TestSerializer. OptionList opl = new TestSerializer. OptionList();
opl.AddOption( new TestSerializer. Option("first", true,"hovertext ",false));
opl.AddOption( new TestSerializer. Option("second" ,true,"hovertex t",true));
myList.AddQuest ion( new TestSerializer. Question("What is the square
root of 2?","selection" ,3,false,opl ) );
TestSerializer. Serialize(myLis t);

Nov 12 '05 #3
last things first. . .
p.s. is .net version 2 changing xml serialization? yes. Well, yes and no. Existing apps will continue to work as is,
unchanged.
But there is a new XML serialization model being introduced.


I then tried your 2nd solution and the calling code above still worked
but I also noticed I could add Options without them being part or
under
a Question....

Option o1 = new Option("first", true,"hovertext ",false);
myList.AddOptio n(o1);
Option o2 = new Option("second" ,true,"hovertex t",true);
myList.AddOptio n(o2);

Gee, that seems wrong. Why is there an AddOption() method on the
QuestionList type?
You should remove it if you don't want to add Options directly to the
QuestionList(). I imagine a QuestionList type like so:

public class QuestionList
{
private ArrayList listQuestions = new ArrayList();

[XmlElement("Que stion")]
public Question[] Questions
{
get {..}
set {..}
}
public int AddQuestion( Question question )
{
return listQuestions.A dd( question );
}
}
Might there be a way to use addoption to add it to the current
question??

Sure! You would have to define QuestionList to have some idea of the
current question. then add a Method in QuestionList like so:

public int AddOption( Option option )
{
return currentQuestion .AddOption( option );
}

Then you could do myList.AddOptio n(...);

But maybe better (clearer for the user of this thing) would be to just
expose the currentQuestion property as a public property. So you would
get:

myList.Current. AddOption(...);

Perhaps I must fiddle with the methods, getter & setters, but I want
to know if you have any ideas or am I going in the right direction
here.


-Dino
Nov 12 '05 #4

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

Similar topics

5
5440
by: Stuart Robertson | last post by:
I am trying to find a solution that will allow me to use XmlSerializer to serialize/deserialize a collection of objects where a given object is shared between two or more other objects, and not create duplicate XML representations of the shared object, but instead use IDREFs to refer to the shared object. The XML I'm trying to produce is as follows (where "href" is an IDREF): <?xml version="1.0" encoding="utf-8"?> <MyRootClass...
8
3580
by: Harris Boyce | last post by:
Hello, I'm trying to use the FOR XML EXPLICIT clause with SQL Server to deserialize data from my database into a strongly-typed collection object that I will use throughout my application. I initially tested my design by building a collection in code and then serializing it to/from an XML file, which worked fine. However, I have hit a brick wall trying to restore the data from SQL Server. I originally had my collection and object
3
7012
by: Anthony Bouch | last post by:
Hi I've been reading using the XmlSerializer with custom collections. I've discovered that when serializing a custom collection (a class that implements ICollection, IList etc.) the XmlSerializer will only serialize the collection items - with the default root as ArrayofMyItems etc. My custom collection class has some additional public properties that I would like to include in the serialization above the items element array (in
2
1798
by: eastsh | last post by:
I have been looking into using the MS application block for configuration management, and I am very happy with the options it provides. Since it stores hashtables, I decided that for configuration data my app needs, I would create strongly typed collections for each config type. For instance, CarCollection dervied from CollectionBase which only accepts items of Car would be set to hashtable key "AppCars". I am running into all kinds of...
2
942
by: magister | last post by:
Hello I got this working but it is not how I really want it, basically I have an xml file which has a root of <test> and can be filled with 3 different types of <question> elements with different attributes, all share a base set of 4, one of the question types can have children with <option> elements, this is how the xml looks after serialization.... If you notice there is an extra <SelectionList> around the <option>'s in the final...
2
6815
by: Kent Boogaart | last post by:
Hello all, I have two simple classes: Item and ItemCollection. Item stores a label for the item and an instance of ItemCollection for all child items. ItemCollection just stores a collection of Items. ItemCollection implements System.Collections.ICollection. When I use XmlSerializer to serialize an instance of ItemCollection, I am unable to control the element names used to contain the item collection and the items therein. Applying...
3
4528
by: Loui Mercieca | last post by:
Hi, I have created a class, named FormField , which basically contains two fields, name and value. I have set the tag before the class and the field is set as an XmlAttribute whil the name as XmlText. In my main class, i have created an arraylist which contains a collection of this class FormField. Basically its: public void Add( string sName, string sValue )
2
5033
by: Jinsong Liu | last post by:
I have following 3 classes public class MyMainClass { MyCollection<MyObject> m_oMyObjectCollection = null; private string m_sID = string.Empty; public MyCollection<MyObject> Collection {
4
1950
by: cwertman | last post by:
Ok the XmlSerializer is nice for my need. BUT I what I need (maybe the XmlSerializer isnt what I need) is to be able to take the following objects A Person who has a collection of Addresses Person (fname)
2
5756
by: =?Utf-8?B?U2hhd24=?= | last post by:
Hi; I would like to be able to use the XMLSerializer to serialize and deserialize a dictionary. is that possible? i know that you can serialize an object that implements the ICollection interface. does the fact that Dictionary inherits from ICollection<cause a problem? Currently i am using a class that inherits from ICollection and it has a Dictionary as it's container. but when it gets to creating the serialized object it blows up. here...
0
11531
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...
1
11298
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,...
0
9863
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8219
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
7390
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
6087
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...
0
6305
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3511
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.