Class ReplaceAction

  • All Implemented Interfaces:
    Action, XPathAction<org.jdom2.Element>

    public class ReplaceAction
    extends AbstractXPathAction<org.jdom2.Element>
    Replaces existing elements returned by an XPath query over an XML document with one or more new elements.
    • Constructor Detail

      • ReplaceAction

        public ReplaceAction​(org.jdom2.xpath.XPathFactory xpathFactory,
                             String xpath,
                             Map<String,​String> prefixToNamespaceMap,
                             List<org.jdom2.Element> contentNodes)
        Construct a new ReplaceAction based on an XPath string using the provided map to map XML prefixes to namespaces within the XPath.
        Parameters:
        xpathFactory - the XPath implementation to use
        xpath - the XPath string
        prefixToNamespaceMap - a map of XML prefixes to namespaces used in the provided XPath
        contentNodes - a list of new elements to use as the replacement
    • Method Detail

      • getContentNodes

        public List<org.jdom2.Element> getContentNodes()
        Retrieves the elements to use as the replacement.
        Returns:
        a list of elements
      • process

        protected void process​(List<org.jdom2.Element> results)
                        throws ActionException
        Replaces existing elements based on the provided XPath results.
        Specified by:
        process in class AbstractXPathAction<org.jdom2.Element>
        Parameters:
        results - a list of XPath results guaranteed to be non-empty
        Throws:
        ActionException - if an error occurs while processing the implemented action