1

I have a piece of code that fills a hashtable with strings, per example: ("name", Oscar). I want to use them to fill (just by memory usage) values and innertexts of XMLAtributes. But there is one problem.

XmlElement Co = newDoc.CreateElement("Co1");

 XmlAttribute series = Co.Attributes.Append(newDoc.CreateAttribute("series"));
         series.InnerText = (string)vector["series"];
         series.Value = (string)vector["series"];
         MessageBox.Show((string)vector["series"]);
         MessageBox.Show(Co.Attributes["series"].InnerText.ToString());
         MessageBox.Show(Co.Attributes["series"].Value.ToString());

When ever I want the system to show me the value or the innertext (within the xml create method this piece of code is in) it has it returns nothing. Then It passes to the next atribute and returns a "Object reference not set to an instance of an object.". The next piece of code is this one:

XmlAttribute folio = Co.Attributes.Append(newDoc.CreateAttribute("folio"));
             folio.InnerText = vector["folio"].ToString();

The error hits in the last line.

In any other place of the class I can see and retrieve the values of the hastable by the .ToString() method and the cast.

It seems that Im not properly getting the value out of my hashtable or there is something I am missing with the XMLAtributes... ¿What is the proper way to do so?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Carlos
  • 57
  • 1
  • 16

1 Answers1

0

You are doing this the hard way:

var folio = Convert.ToString(vector["folio"]);
Co.SetAttribute("folio", folio);

There is no need to worry about things like InnerText.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • Hey man, thanks for your response but I am getting the same result! – Carlos Oct 24 '13 at 21:35
  • @Carlos are you sure that `vector` contains an entry for `folio` ? – Marc Gravell Oct 25 '13 at 07:11
  • Yes, I have made a method to show me that It does have the values (A public void). Only when I execute public void createXML() (The one that creates the XML) in that specific method I cant see my Hashtable values, nor any public string values of the same class. – Carlos Oct 25 '13 at 20:47
  • it would seem that in the createXML my global variables (or just external ones) get nullified when inserted into an attribute value. – Carlos Oct 25 '13 at 22:11