Check Xml tag exist in xpath.

getmore

New Member
I am trying to get value from Xml file using xpath. Here is my code:\[code\]XElement docQuote = XElement.Parse(Financial);string result= docQuote.XPathSelectElement("//ns:Quote",nsmgr).ToString(SaveOptions.DisableFormatting);\[/code\]This is working fine when \[code\]Quote\[/code\] Xml node exist in XML file and return value in between \[code\]Quote\[/code\] tags. However Quote xml tag not exist in the XMl file it generates and exception. \[code\]Object reference not set to an instance of an object.\[/code\]I have tried to check NULL as below:\[code\]if(docQuote.XPathSelectElement("//ns:Quote",nsmgr) != null\[/code\])and\[code\]if(docQuote.XPathSelectElement("//ns:Quote",nsmgr) != null).value != null)\[/code\]However it doesn't avoid the execution when null. Please help me to avoid execution when Xml tag not exist.
 
Back
Top