Click here to Skip to main content
16,005,121 members
Home / Discussions / C#
   

C#

 
QuestionRe: XML parsing in c# Pin
aruna_koride18-Sep-06 18:32
aruna_koride18-Sep-06 18:32 
QuestionMainForm not here for working in Code? Pin
xenotronic00717-Sep-06 15:38
xenotronic00717-Sep-06 15:38 
AnswerRe: MainForm not here for working in Code? Pin
Christian Graus17-Sep-06 15:48
protectorChristian Graus17-Sep-06 15:48 
GeneralRe: MainForm not here for working in Code? Pin
xenotronic00718-Sep-06 13:25
xenotronic00718-Sep-06 13:25 
GeneralRe: MainForm not here for working in Code? Pin
Christian Graus18-Sep-06 13:45
protectorChristian Graus18-Sep-06 13:45 
QuestionAdd LinkLabel to panal Pin
Muller217-Sep-06 7:38
Muller217-Sep-06 7:38 
AnswerRe: Add LinkLabel to panal Pin
Stefan Troschuetz17-Sep-06 8:18
Stefan Troschuetz17-Sep-06 8:18 
QuestionList collection all elements the same! Help! Pin
TommySu17-Sep-06 7:26
TommySu17-Sep-06 7:26 
I'm trying to create an object that will deserialize xml into a dictionary. So far I have most of the stuff working however when I do something like

this.myList.Add(myItem);

I expect to get a new item that in my list that is equal to myItem. However, for some reason the List updates all of the containing items in the List to equal the most recently added item.

Any idea what's going on?

Here is a the serializable class in question if it helps:
    public class WeatherCities : IXmlSerializable<br />
    {<br />
        [XmlElement]<br />
        public List<city> City;<br />
        public WeatherCities()<br />
        {<br />
        }<br />
<br />
        public class city<br />
        {<br />
            private string cityName;<br />
            private string cityCode;<br />
<br />
            [XmlElement]<br />
            public string CityName<br />
            {<br />
                get { return cityName; }<br />
                set { cityName = value; }<br />
            }<br />
<br />
            [XmlElement]<br />
            public string CityCode<br />
            {<br />
                get { return cityCode; }<br />
                set { cityCode = value; }<br />
            }<br />
<br />
            const string NS = "http://www.develop.com/xml/serialization";<br />
<br />
            [XmlElement]<br />
            public IDictionary<string, string> LocalizedNames;<br />
<br />
        }<br />
<br />
        public void ReadXml(XmlReader r)<br />
        {<br />
            this.City = new List<city>();<br />
            while (r.Read())<br />
            {<br />
                city myCity = new city();<br />
                myCity.LocalizedNames = new Dictionary<string, string>();<br />
<br />
                while (r.Name == "City")<br />
                {<br />
                    if (r.NodeType == XmlNodeType.EndElement)<br />
                        r.Read();<br />
                    else<br />
                    {<br />
                        r.Read();<br />
                        bool bLocalizedNameFound = false;<br />
                        myCity.CityCode = "";<br />
                        myCity.CityName = "";<br />
                        myCity.LocalizedNames.Clear();<br />
                        while (!bLocalizedNameFound)<br />
                        {<br />
                            switch (r.Name)<br />
                            {<br />
                                case "CityName":<br />
                                    myCity.CityName = r.ReadElementString();<br />
                                    break;<br />
                                case "CityCode":<br />
                                    myCity.CityCode = r.ReadElementString();<br />
                                    break;<br />
                                case "LocalizedNames":<br />
                                    bLocalizedNameFound = true;<br />
                                    break;<br />
                            }<br />
                        }<br />
<br />
                        string locale = "";<br />
                        string localizedname = "";<br />
                        bool localefound = false;<br />
                        bool endlocalnamefound = false;<br />
<br />
                        r.Read(); //Get past LocalizedNames<br />
                        r.Read(); //Get past LocalName<br />
<br />
                        while (r.NodeType != XmlNodeType.EndElement && !endlocalnamefound)<br />
                        {<br />
                            switch (r.Name)<br />
                            {<br />
                                case "Locale":<br />
                                    locale = r.ReadElementString();<br />
                                    localefound = true;<br />
                                    break;<br />
                                case "LocalizedName":<br />
                                    localizedname = r.ReadElementString();<br />
                                    break;<br />
                            }<br />
<br />
                            if (localefound == true && localizedname != "")<br />
                            {<br />
                                myCity.LocalizedNames.Add(locale, localizedname);<br />
                                localefound = false;<br />
                                localizedname = "";<br />
                            }<br />
<br />
                            if (r.NodeType == XmlNodeType.EndElement && r.Name == "LocalName")<br />
                            {<br />
                                r.Read(); // Get past LocalName EndElement<br />
                                if (r.Name == "LocalizedNames")<br />
                                    endlocalnamefound = true; // Get ready to exit loop.<br />
                                r.Read(); // Get past LocalName StartElement<br />
                            }<br />
                        }<br />
<br />
                        this.City.Add(myCity);<br />
                    }<br />
                }<br />
            }<br />
        }<br />
<br />
        // Not used but needed to make compiler happy<br />
        public void WriteXml(XmlWriter w)<br />
        {<br />
            //w.WriteStartElement("dictionary", NS);<br />
            //foreach (object key in LocalizedNames.Keys)<br />
            //{<br />
            //    object value = LocalizedNames[key];<br />
            //    w.WriteStartElement("item", NS);<br />
            //    w.WriteElementString("key", NS, key.ToString());<br />
            //    w.WriteElementString("value", NS, value.ToString());<br />
            //    w.WriteEndElement();<br />
            //}<br />
            //w.WriteEndElement();<br />
        }<br />
        public System.Xml.Schema.XmlSchema GetSchema()<br />
        {<br />
            return LoadSchema();<br />
        }<br />
        private System.Xml.Schema.XmlSchema LoadSchema()<br />
        {<br />
            //throw new Exception("The method or operation is not implemented.");<br />
            return null;<br />
        }<br />
<br />
    }<br />
}

AnswerRe: List collection all elements the same! Help! Pin
Stefan Troschuetz17-Sep-06 8:09
Stefan Troschuetz17-Sep-06 8:09 
GeneralRe: List collection all elements the same! Help! Pin
TommySu17-Sep-06 17:46
TommySu17-Sep-06 17:46 
AnswerRe: List collection all elements the same! Help! Pin
Guffa17-Sep-06 9:32
Guffa17-Sep-06 9:32 
QuestionEsc Pin
TAREQ F ABUZUHRI17-Sep-06 6:38
TAREQ F ABUZUHRI17-Sep-06 6:38 
AnswerRe: Esc Pin
Amar Chaudhary17-Sep-06 7:00
Amar Chaudhary17-Sep-06 7:00 
Questiona problem with c# IDE Pin
Green Fuze17-Sep-06 5:57
Green Fuze17-Sep-06 5:57 
AnswerRe: a problem with c# IDE Pin
Vikram A Punathambekar17-Sep-06 6:12
Vikram A Punathambekar17-Sep-06 6:12 
GeneralRe: a problem with c# IDE Pin
Green Fuze17-Sep-06 7:29
Green Fuze17-Sep-06 7:29 
AnswerRe: a problem with c# IDE Pin
Vikram A Punathambekar17-Sep-06 6:13
Vikram A Punathambekar17-Sep-06 6:13 
QuestionPrint Pin
MHASSANF17-Sep-06 5:20
MHASSANF17-Sep-06 5:20 
AnswerRe: Print Pin
Green Fuze17-Sep-06 7:34
Green Fuze17-Sep-06 7:34 
QuestionPort Pin
mehrdadc4817-Sep-06 4:16
mehrdadc4817-Sep-06 4:16 
AnswerRe: Port Pin
Jakob Farian Krarup17-Sep-06 19:27
Jakob Farian Krarup17-Sep-06 19:27 
GeneralRe: Port Pin
mehrdadc4817-Sep-06 23:17
mehrdadc4817-Sep-06 23:17 
GeneralRe: Port Pin
Jakob Farian Krarup18-Sep-06 0:06
Jakob Farian Krarup18-Sep-06 0:06 
QuestionSocket Pin
mehrdadc4817-Sep-06 4:06
mehrdadc4817-Sep-06 4:06 
AnswerRe: Socket Pin
Ravi Bhavnani17-Sep-06 5:10
professionalRavi Bhavnani17-Sep-06 5:10 

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.