Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Is there any way (regex or similar, c# preferred) to detect if an XPath expression is correct before using it?
I have been googling for some time and nothing seems to appear.
Thanks in advance! Carlos.
尝试一下,如果抛出 XPathException,则意味着您的 XPath 在语法上是错误的。
XmlDocument doc = new XmlDocument(); XPathNavigator nav = doc.CreateNavigator(); try { var res = nav.Compile(xpath); // ... } catch (XPathException e) { // Handle exception }