Design Strongly typed object from XML
Currently we run stored procedures based on "SQL XML" where in we send xml string
as input to stored procedures and get the response from stored procedures as xml
. For a simple demonstration of user logging into application here is how it is done
<Request Type="" CRUD="C/R/U/D">`
<Users>
<UserName></UserName>
<Password></Password>
</Users>
</Request>
don't mind about the response from database because that we can change to anything we desired to. It is this construction of xml that we find too intimidating. Below is code we follow
StringBuilder _sbXml = new StringBuilder();
_sbXml.AppendLine("<Request Type='' CRUD=''>");
_sbXml.AppendLine("<Users>");
_sbXml.AppendLine("<UserName>"+ usernameVariable +"</UserName>");
_sbXml.AppendLine("<Password>"+ passwordVariable +"</Password>");
_sbXml.AppendLine("</Users>");
DataTier.BeginRequest(_sbXml.ToString());
we tried abstracting things into methods but again we never solved the problem that we wanted to, just hid them somewhere.
So we concluded that strong typing is necessary for each request to avoid any typo's,undesired behavior, avoid hand coded xml and maintainable
. Hence the question
How can i abstract away this form of building xml's
XSD tool can generate class modelling xml data(Related post), is the class that is generated using the tool adaptive
for long run?
Abstracting string xml to Typed classes is advisable? Has anyone had success doing something that i am trying to do now?Which did you feel comfortable with?
Above is just a single database call, we got same for all the database calls. We are into big mess maintaining for sure.
Using C# 2.0
.NET 2.0
SQL Server 2005
Visual Studio 2005
There are two problems here:
So, I would suggest:
XmlDocument
etc(It's not really clear what you meant by "we concluded that a class would solve things" or "I saw the related post and generated class" so it's possible that I'm missing the point. If so, please edit your question to clarify.)