Flow action remove-content

The remove-content action is used to remove nodes from a DOM. By default it will use fit://request/content for input and output.

Syntax

  • Either xpath="..." or css-selector="..." for selecting nodes in the document (must have exactly one).
  • in="..." to define the input location (optional, default is fit://request/content).
  • out="..." to define the output location (optional, default is fit://request/content).

Usage

The action reads the in content, changes the document by removing nodes selected by the given xpath or css-selector, and writes the changed document to out. If the document node is selected (for example by using xpath="/") the node will not be removed. Instead it will simply be ignored when the selected nodes are removed.

Check the css selector documentation for more information regarding support und utilization.

Example

flow.xml:

<flow><remove-content css-selector="aside" if="viewport/width &lt; 500"/></flow>

Input:

<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    <header>
      <h1>My Blog</h1>
    </header>
    <article>
      <h1>My Blog Post</h1>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
      eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
    </article>
    <aside>
      <h2>Blogroll</h2>
      <ul>
        <li><a href="…">My Friend</a></li>
        <li><a href="…">My Other Friend</a></li>
        <li><a href="…">My Best Friend</a></li>
      </ul>
    </aside>
  </body>
</html>

Output if the condition evaluates to true:

<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    <header>
      <h1>My Blog</h1>
    </header>
    <article>
      <h1>My Blog Post</h1>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
      eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
    </article>
  </body>
</html>

Errors

The following errors are considered non-fatal. The flow will continue, no content will be written to out.

  • Neither a xpath nor a css-selector attribute is specified.
  • The xpath and css-selector attributes are specified both.
  • The xpath or css-selector attribute contains an invalid expression.
  • The in document is missing, empty or no DOM.