views:

7

answers:

1

I have a simple Xml Node that I need to recreate

<Division ID="123">Division Name</Division> 

But when I create the class as

public class Division
{
    [XmlAttribute]
    public string Id { get; set; }

    [XmlText]
    public string Description { get; set; }
}

I get

<Division>Division Name</Division> 

The Id vanishes.

How can I make this work?

+1  A: 

Works on my machine


Division d = new Division()
{
    Id = "1",
    Description = "Description"
};

FileStream fs = new FileStream("test.txt", FileMode.Create);
TextWriter writer = new StreamWriter(fs, new UTF8Encoding());


XmlSerializer xs = new XmlSerializer(typeof(Division));
xs.Serialize(writer, d);
writer.Close();

<?xml version="1.0" encoding="utf-8"?>
<Division xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     
       xmlns:xsd="http://www.w3.org/2001/XMLSchema" Id="1">Description</Division>
Nix
I had a bug later in code that was stripping them... *sigh*
Chad
Friday is almost here... you'll be alright..
Nix