Click here to Skip to main content
15,892,927 members
Home / Discussions / C#
   

C#

 
GeneralSystem.NullException Error Pin
tcombs0714-Apr-08 8:26
tcombs0714-Apr-08 8:26 
GeneralRe: System.NullException Error Pin
Luc Pattyn14-Apr-08 9:01
sitebuilderLuc Pattyn14-Apr-08 9:01 
GeneralRe: System.NullException Error Pin
tcombs0714-Apr-08 9:29
tcombs0714-Apr-08 9:29 
GeneralRe: System.NullException Error Pin
Luc Pattyn14-Apr-08 9:56
sitebuilderLuc Pattyn14-Apr-08 9:56 
GeneralSQL statement Pin
vanessa12314-Apr-08 8:08
vanessa12314-Apr-08 8:08 
GeneralRe: SQL statement Pin
Rob Philpott14-Apr-08 8:18
Rob Philpott14-Apr-08 8:18 
GeneralRe: SQL statement Pin
Rob Philpott14-Apr-08 8:19
Rob Philpott14-Apr-08 8:19 
GeneralSerializing object. Need Help. Pin
zaboboa14-Apr-08 6:33
zaboboa14-Apr-08 6:33 
Hi!

I have the following classes:
<br />
[XmlRoot("shoppingList")]<br />
public class ShoppingList<br />
{<br />
	private ArrayList listShopping;<br />
<br />
	public ShoppingList()<br />
	{<br />
		listShopping = new ArrayList();<br />
	}<br />
<br />
	[XmlElement("item")]<br />
	public Item[] Items<br />
	{<br />
		get<br />
		{<br />
			Item[] items = new Item[listShopping.Count];<br />
			listShopping.CopyTo(items);<br />
			return items;<br />
		}<br />
		set<br />
		{<br />
			if (value == null) return;<br />
			Item[] items = (Item[])value;<br />
			listShopping.Clear();<br />
			foreach (Item item in items)<br />
				listShopping.Add(item);<br />
		}<br />
	}	<br />
<br />
	public int AddItem(Item item)<br />
	{<br />
		return listShopping.Add(item);<br />
	}<br />
}<br />
<br />
// Items in the shopping list<br />
public class Item<br />
{<br />
	[XmlElement("name")]<br />
	public string name;<br />
	[XmlElement("price")]<br />
	public double price;<br />
	<br />
	public Item()<br />
	{<br />
	}<br />
<br />
	public Item(string Name, string Price)<br />
	{<br />
		name = Name;<br />
		price = Convert.ToDouble(Price);<br />
	}<br />
}<br />


When I Serialize it I get the following XML back:
<br />
<?xml version="1.0" encoding="utf-8"?><shoppingList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><item><name>eggs</name><price>1.49</price></item><item><name>bread</name><price>0.99</price></item></shoppingList><br />


As you can see from the definition of the ShoppingList class, I have an attribute [XmlElement] defined before the Items property, with the "items" name. So in my XML every element is <item>. What can I do, so that when I serialize my ShoppingList object, each "item" element will have it's own name.
So, one element will be "Table1", next will be "Table2", and so on.

Any help greatly appreciated.
Thank you very much.
GeneralRe: Serializing object. Need Help. Pin
Zoltan Balazs14-Apr-08 7:23
Zoltan Balazs14-Apr-08 7:23 
GeneralC#: WriteEncrypedFileRaw Pin
rreeeddbb14-Apr-08 6:28
rreeeddbb14-Apr-08 6:28 
GeneralWindows Service Installer Pin
Madmaximus14-Apr-08 6:28
Madmaximus14-Apr-08 6:28 
General"The given path's format is not supported." Pin
shivapriyak14-Apr-08 4:36
shivapriyak14-Apr-08 4:36 
GeneralRe: "The given path's format is not supported." Pin
Mark J. Miller14-Apr-08 4:48
Mark J. Miller14-Apr-08 4:48 
GeneralRe: "The given path's format is not supported." Pin
J4amieC14-Apr-08 5:42
J4amieC14-Apr-08 5:42 
GeneralRe: "The given path's format is not supported." Pin
Mark J. Miller14-Apr-08 6:11
Mark J. Miller14-Apr-08 6:11 
GeneralRe: "The given path's format is not supported." Pin
J4amieC14-Apr-08 6:20
J4amieC14-Apr-08 6:20 
GeneralRe: "The given path's format is not supported." Pin
Mark J. Miller14-Apr-08 6:29
Mark J. Miller14-Apr-08 6:29 
GeneralRe: "The given path's format is not supported." Pin
PIEBALDconsult14-Apr-08 8:33
mvePIEBALDconsult14-Apr-08 8:33 
GeneralRe: "The given path's format is not supported." Pin
Luc Pattyn14-Apr-08 5:11
sitebuilderLuc Pattyn14-Apr-08 5:11 
QuestionHow to retrieve the printer's device context in C# ? Pin
Faysal14-Apr-08 4:03
Faysal14-Apr-08 4:03 
GeneralRe: How to retrieve the printer's device context in C# ? Pin
Luc Pattyn14-Apr-08 7:41
sitebuilderLuc Pattyn14-Apr-08 7:41 
QuestionOpen new form Pin
Alessandra7714-Apr-08 3:37
Alessandra7714-Apr-08 3:37 
GeneralRe: Open new form Pin
A AntonySP14-Apr-08 3:40
A AntonySP14-Apr-08 3:40 
GeneralRe: Open new form Pin
Alessandra7714-Apr-08 3:43
Alessandra7714-Apr-08 3:43 
GeneralRe: Open new form Pin
Christian Graus14-Apr-08 3:46
protectorChristian Graus14-Apr-08 3:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.