Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C# XML Problem

Status
Not open for further replies.

flnhst

Programmer
Aug 9, 2005
12
NL
I have these classes:

Code:
	public class CHardware
	{
        [XmlElement("HardwareID")]
        public int HardwareID;
        [XmlElement("HardwareName")]
        public string HardwareName;
        [XmlElement("HardwareType")]
        public string HardwareType;
        [XmlElement("HardwareCost")]
        public int HardwareCost;

        [XmlElement("Params")]
        public HybridDictionary Params;

		public CHardware()
		{
			Params = new HybridDictionary();
		}
	}

	[XmlRoot("HardwareList")]
    public class CHardwareList
	{
        [XmlArray("Hardwares")]
        [XmlArrayItem("Hardware", typeof(CHardware))]
        CHardware[] HardwareList;

        [XmlElement("Length")]
        int Length;

		public CHardwareList()
		{	
			HardwareList = new CHardware[128];

			Length = 0;
		}
    // ... Functions ...
    }

But everytime i serialize CHardwareList, the file ALWAYS looks like this:

Code:
<?xml version="1.0"?>
<HardwareList xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xmlns:xsd="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] />

Whatever i try there is nothing to be found in the file but this. Is there any solution to this?
 
You can add additional namespaces via the XmlSerializerNamespaces class, but I don't think you can remove those.

Chip H.


____________________________________________________________________
Donate to Katrina relief:
If you want to get the best response to a question, please read FAQ222-2244 first
 
What i mean when i serialize a instance of the class CHardwareList (With some data, etc), There is nothing in the XML file but those lines.
 
Code:
		public void WriteToFile(CHardwareList HardwareList, FileMode FMode)
		{
			Stream stream = File.Open(FileName, FMode);
                        XmlSerializer bformatter = new XmlSerializer(typeof(CHardwareList));

			bformatter.Serialize(stream, HardwareList);

			stream.Close();
		}

This is the code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top