jim_bob_jim
asked on
asp.net c# create dynamic xml from database
Hi guys,
I wonder can you help,
Im working off of the following example that creates xml to be passed back to the client based on a string array with populated names.
here is the coded example from the following book Im working off "Ajax for Web Application Developers"
private void SearchUsers()
{
string request = Request["request"].ToStrin g();
string usernameXml = "";
string[] usernames = new string[3] { "Kris Hadlock", "Grace Hopper", "Pi Sheng" };
foreach (string username in usernames)
{
if (username.ToLower().Substr ing(0, request.Length) == request.ToLower())
{
usernameXml += "<username><![CDATA[" + username + "]]></username>";
}
}
usernameXml = "<?xml version='1.0' encoding='iso-8859-1' ?><usernames>" + usernameXml + "</usernames>";
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(usernameXml);
xDoc.Save(Response.OutputS tream);
}
I wish to achieve the same except I want to pull the usernames from the databse as part of a query and then parse them into the xml document.
Can someone show me how I could do this please?
Thanks very much!
Jimbo
I wonder can you help,
Im working off of the following example that creates xml to be passed back to the client based on a string array with populated names.
here is the coded example from the following book Im working off "Ajax for Web Application Developers"
private void SearchUsers()
{
string request = Request["request"].ToStrin
string usernameXml = "";
string[] usernames = new string[3] { "Kris Hadlock", "Grace Hopper", "Pi Sheng" };
foreach (string username in usernames)
{
if (username.ToLower().Substr
{
usernameXml += "<username><![CDATA[" + username + "]]></username>";
}
}
usernameXml = "<?xml version='1.0' encoding='iso-8859-1' ?><usernames>" + usernameXml + "</usernames>";
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(usernameXml);
xDoc.Save(Response.OutputS
}
I wish to achieve the same except I want to pull the usernames from the databse as part of a query and then parse them into the xml document.
Can someone show me how I could do this please?
Thanks very much!
Jimbo
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much. I had got so close and your answer explained exactly what I was missing.
Much appreciated!!
Much appreciated!!
OleDbConnection objConn = new OleDbConnection(Configurat
You then need to define your connection in the AppSettings. If using .NET 2 then you can use the actual ConnectionStrings section instead of AppSettings