Class AddAttributeAction

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

    public class AddAttributeAction
    extends AbstractXPathAction<org.jdom2.Element>
    Adds a new XML attribute to an exiting element.
    • Constructor Detail

      • AddAttributeAction

        public AddAttributeAction​(org.jdom2.xpath.XPathFactory xpathFactory,
                                  String xpath,
                                  Map<String,​String> prefixToNamespaceMap,
                                  String namespace,
                                  String name,
                                  String value)
        Construct a new AddAttributeAction based on an XPath string using the provided map to map XML prefixes to namespaces.
        Parameters:
        xpathFactory - the XPath implementation to use
        xpath - the XPath string
        prefixToNamespaceMap - a map of XML prefixes to namespaces used in the provided XPath
        namespace - the namespace of the new attribute or null if the attribute has no namespace
        name - the name of the new attribute
        value - the value of the new attrubute
    • Method Detail

      • getNamespace

        public String getNamespace()
        Retrieve the namespace URI to use for the new attribute.
        Returns:
        the namespace URI
      • getName

        public String getName()
        Retrieve the name of the new attribute.
        Returns:
        the attribute's name
      • getValue

        public String getValue()
        Retrieve the new attribute's value.
        Returns:
        the new attributes value
      • process

        protected void process​(List<org.jdom2.Element> results)
                        throws ActionException
        Appends an attribute to each resulting Element.
        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