Using XPathDocument

using Systm.XML.Xpath

//creates an instance of XPathDocument class and loads xml
if (System.IO.File.Exists(Server.MapPath("/portal/BrowserCookieValidation.xml")))
{
XPathDocument doc = new XPathDocument(Server.MapPath("BrowserCookieValidation.xml"));
//An XPathNavigator object acts like a cursor, addressing a node in the XML document at a time
XPathNavigator nav = doc.CreateNavigator();
string message = String.Empty;
// Compile a standard XPath expression
XPathExpression expr = nav.Compile("/CookieValidation/OutCompany[@OCID=" + OCID.ToString() + "]");
//select node with ocid = 131
XPathNodeIterator iterator = nav.Select(expr);

//if node is found, count would be greater than 0 and company specific messsaage would come
if (iterator.Count > 0)
{ //Iterate through the selected nodes
while (iterator.MoveNext())
{
//if attribute is not there but node is there,null will be returned
if (iterator.Current.GetAttribute("ErrorMessage", string.Empty) != null)
message = iterator.Current.GetAttribute("ErrorMessage", string.Empty);
}
}
else //get default message
{
message = GetDefaultMessage(doc, nav);
}
//in case ocid node is there, but blank errormessage, bring default message
if (string.IsNullOrEmpty(message))
message = GetDefaultMessage(doc, nav);

//put value in the labbel
msgContainer.Text = message;

1 comment:

Nhà Xinh said...

Nếu bạn đang muốn đăng tin bán nhà hay bán đất hoặc bạn muốn ban nha quan 12 , nha dat xinh thì hãy đến với chúng tôi rao vat mien phi, với chất lương hàng đầu chúng tôi sẽ giúp các bạn , đăng tin và xem các khu vực nha dat go vap, nha dat quan 9, nha dat thu duc , nha dat binh tan , nha dat tan phu , nha dat tan binh và các khu vực khác trên NguyenManhKha toàn quốc với uy tín và hiệu quả cao khi bạn đến với chúng tôi.