To find the fragment of an XML document that you need, you need the following XPath expression:
/APIS/API/field[@Username='username1' and @UserPassword='password1']
This will either return something if the username and password match - or not if they do not.
An XPath expression is just a string - you can build it dynamically with the values โโthat were entered in the form field, for example.
If you tell us which language / environment you are in, the code samples posted here are likely to become more specific.
This is the way to do it in C # (similar to VB.NET):
// make sure the following line is included in your class using System.Xml; XmlDocument xmldoc = new XmlDocument(); xmldoc.Load("your XML string or file"); string xpath = "/APIS/API/field[@Username='{0}' and @UserPassword='{1}']"; string username = "username1"; string password = "password1"; xpath = String.Format(xpath, username, password); XmlNode userNode = xmldoc.SelectSingleNode(xpath); if (userNode != null) { // found something with given user name and password } else { // username or password incorrect }
Remember that neither usernames nor passwords can contain single quotes, otherwise the above example will fail. Here is some information about this feature .
There is also a Microsoft How-To: HOW: Use the System.Xml.XmlDocument class to execute XPath queries in Visual C # .NET
Tomalak
source share