Metreeca MIME
    Preparing search index...

    Function xpath

    Creates an XPath selector.

    • Creates an XPath selector task.

      The task converts a feed of parsed X/HTML trees into a feed of XPath selectors, one selector per tree, so that downstream tasks select nodes by expression rather than walking the tree.

      Note

      • Incremental: each selector is emitted as soon as its tree is drawn, so endless sources are processed for as long as the feed is consumed.
      • Streaming: trees are processed one at a time and none is retained, so memory use doesn't grow with the length of the feed; each selector keeps its target tree alive for as long as it is referenced.
      • Stateless: each tree is processed independently, so the result doesn't depend on how the feed is split across nested feeds or runs.

      Returns Task<AnyNode, XPath>

      A task converting a feed of parsed X/HTML trees into a feed of XPath selectors

      Error While the feed is consumed, if the source feed fails

    • Creates an XPath mapping task.

      The task converts a feed of parsed X/HTML trees into a feed of mapped results, one result per tree, so that downstream tasks work on the shape they need rather than on the markup.

      Note

      • Incremental: each result is emitted as soon as its tree is drawn, so endless sources are processed for as long as the feed is consumed.
      • Streaming: trees are processed one at a time and released once mapped, so memory use doesn't grow with the length of the feed.
      • Stateless: each tree is mapped independently, so the result doesn't depend on how the feed is split across nested feeds or runs.

      Type Parameters

      • V

        The type of the results mapped from incoming trees

      Parameters

      • mapper: (path: XPath) => V

        The mapping function, applied to an XPath selector targeting the tree being processed

      Returns Task<AnyNode, V>

      A task converting a feed of parsed X/HTML trees into a feed of mapped results

      Error While the feed is consumed, if the source feed fails or mapper throws, including a SyntaxError for a malformed expression

      const events = xpath(path => ({

      title: path("//h1").map(string),
      links: path("//a/@href").map(link)

      }));
    • Creates an XPath selector over given nodes.

      Targets nodes already at hand, outside a feed, with the same selection semantics as the selectors emitted by the feed tasks.

      Important

      A call without nodes, including one spreading an empty list, creates a selector task over a feed rather than a selector with an empty target set.

      Parameters

      • ...nodes: readonly Target[]

        The target nodes, in selection order

      Returns XPath

      An immutable selector targeting nodes