I have spent quite some time on this and have been scouring the net for help, but I couldn't find exactly the problem I'm having and thought someone might be able to steer me in the right direction.
Ok here is my problem - A user selects a value from a drop down box on a ASP.NET page, along with other data. When the user clicks next, I want to verify that the selection that the user has made exists in the xml file. I am doing this to prevent any unwanted sql injections etc. So essentially, if the value selected exists in the xml document, the page validates otherwise it displays an error. There are a number of xml documents in the application, but I have just posted one example and the the xml file.
<?xml version="1.0" encoding="utf-8" ?> <titles> <title text="Mr" value="Mr"></title> <title text="Mrs" value="Mrs"></title> <title text="Miss" value="Miss"></title> </titles>
//reads thru the relevant xml file and checks to see if the value
//selected by the applicant exists in the xml document
//where value is the selected value of the drop down box
//and source is the name of the xml file that contains the
//data.
private bool checkXML(String value, String source)
{
Boolean valid = false;
// string msg;
String fileName = HttpContext.Current.Server.MapPath("/App_Data/XMLfiles/" + source + ".xml");
XElement xml = XElement.Load(@fileName);
var query = from c in xml.Elements()
select c;
foreach (string i in query.Attributes())
{
if (i == value)
{
valid = true;
}
} return valid;
}
Everything works up until the foreach, where it doesn't appear to be looping thru everything and it only returns the first value in the xml file.
Thanks in advance
Bec

New Topic/Question
Reply



MultiQuote






|