I've been doing a lot of work on preparing an existing product for conversion to our new platform. One thing that the existing product has is a lot of data contained in XML, some of which is now going to exist as real columns in the database. Most of this XML is actually NVPs so it looks like this:
<elements><element elementid="name" responsetext="value">element><element elementid="anothername" responsetext="some other value">element>elements>
Now it is very possible to process through this XML, I'm just lazy so I turn it into a Hashtable so I can easily determine if an NVP exists and easily remove an NVP when I'm done with it.
private Hashtable XML2Hash(string XMLBlock)
{
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(XMLBlock);
XmlNode WalkMe = null;if (xdoc.ChildNodes[1] != null)
WalkMe = xdoc.ChildNodes[1].FirstChild;if (WalkMe == null && xdoc.FirstChild.FirstChild != null)
WalkMe = xdoc.FirstChild.FirstChild;
Hashtable retVal = new Hashtable();foreach (XmlNode x in WalkMe.ChildNodes)
{
retVal.Add(x.Attributes["ElementId"].Value, x.Attributes["ResponseText"].Value);
}
return retVal;
}