Register
Wednesday, September 08, 2010
 
 DBAs And ProgrammersBlog
  
News! Minimize
   
 
 Print   
 
Misc Blog Stuff Minimize
   
 
 Print   
 
The Reluctant DBA Minimize
 
 
 
 Print   
 
Reluctant DBA Minimize
   
 
  
 
Reluctant DBA Minimize
   
 
  
 
The Reluctant DBA Minimize
 
May21

Written by:CarpDeus
5/21/2009 2:58 PM 

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;
}

Copyright ©2009 Carp Deus

Tags:

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment  Cancel 
 
 
  
 
Privacy Statement | Terms Of Use Copyright 2001-2008 by ReluctantDBA.com