using System.Xml; using JetBrains.Annotations; using WireMock.Validation; using Wmhelp.XPath2; namespace WireMock.Matchers { /// /// XPath2Matcher /// /// public class XPathMatcher : IMatcher { private readonly string _pattern; /// /// Initializes a new instance of the class. /// /// The pattern. public XPathMatcher([NotNull] string pattern) { Check.NotNull(pattern, nameof(pattern)); _pattern = pattern; } /// /// Determines whether the specified input is match. /// /// The input. /// /// true if the specified input is match; otherwise, false. /// public bool IsMatch(string input) { var nav = new XmlDocument { InnerXml = input }.CreateNavigator(); object result = nav.XPath2Evaluate($"boolean({_pattern})"); return true.Equals(result); } } }