Class XmlXPathTemplateHelper

java.lang.Object
org.mockserver.templates.engine.helpers.XmlXPathTemplateHelper

public class XmlXPathTemplateHelper extends Object
XPath evaluation helper for templates: evaluate an XPath expression against an XML document and return the string result. Uses the JDK javax.xml.xpath APIs (these stay in the javax namespace per the Java compatibility policy — they are JDK classes, not the jakarta-migrated EE ones).

The XML parser is hardened against XXE by disabling DOCTYPE declarations and external entity resolution.

  • Constructor Details

    • XmlXPathTemplateHelper

      public XmlXPathTemplateHelper()
  • Method Details

    • evaluate

      public String evaluate(String xml, String xpathExpression)
      Evaluates the given XPath expression against the supplied XML string and returns the result as a string. Returns an empty string for null inputs or when the document cannot be parsed / the expression is invalid.
    • toString

      public String toString()
      Overrides:
      toString in class Object