xml-conduit-selectors-0.2.0.0: jQuery-style CSS selectors for xml-conduit
Safe HaskellNone
LanguageHaskell2010

Text.XML.Selectors.Parsers.JQ

Description

This module provides functions for parsing jQuery/CSS selectors into Axis functions.

The following selectors are currently supported:

  • Any selector (*): Select any node.
  • Element name selector (div): Select all elements of the given element name.
  • Descendant selector (a b): Select descendants of all the nodes matching the LHS selector that match the RHS selector.
  • Child selector (a > b): Select children of all the nodes matching the LHS selector that match the RHS selector.
  • Following sibling selector (a ~ b): Select siblings of all the nodes matching the LHS selector that match the RHS selector.
  • Adjacent sibling selector (a + b): Select directly adjacent siblings of all the nodes matching the LHS selector that match the RHS selector.
  • Alternative selector (a , b): Select all nodes that match the LHS selector, and also all the nodes that match the RHS selector.
  • Class selector (.classname): Select all elements whose class attribute contains the given class name.
  • ID selector (#id): Select the element whose id attribute matches the given ID. Note that while in a well-formed XML document, each ID may only be used once, this selector will happily return multiple nodes if the target document is not well-formed, or when it is combined with other selectors that cause the same element to be matched via multiple paths (see also the note below).
  • Attribute-exists selector ([attr]): Select elements that have an attribute of the given name.
  • Attribute-is selector ([attr="value"]): Select elements whose attr attribute is exactly equal to the given value.
  • Attribute-is-not selector ([attr!="value"]): Select elements whose attr attribute is not exactly equal to the given value.
  • Attribute-starts-with selector ([attr^="value"]): Select elements whose attr attribute begins with the given value.
  • Attribute-ends-with selector ([attr$="value"]): Select elements whose attr attribute ends with the given value.
  • Attribute-contains selector ([attr*="value"]): Select elements whose attr attribute contains the given value.
  • Attribute-contains-word selector ([attr~="value"]): Select elements whose attr attribute contains the given value between word boundaries. Word boundaries are the very beginning and end of the value, as well as any nonzero number of whitespace characters.
  • Attribute-contains-prefix selector ([attr|="value"]): Select elements whose attr attribute contains the given value as a prefix. A prefix is either the entire value itself, or the given value plus a hyphen-minus character (-) at the very beginning of the attribute value.
  • Not selector (:not(a)): Select all elements that do not match the argument selector.
  • Has selector (:has(a)): Select all elements that have relatives that match the argument selector. A relationship (+, ~, >) can be given at the start of the argument; if none is given, the descendant relationship is the default.
  • First-child selector (:first-child): Select all elements that are the first child of their respective parent.
  • Last-child selector (:last-child): Select all elements that are the last child of their respective parent.
  • Nth-child selector (:nth-child(n)): Select all elements that are the n-th child (1-based) of their respective parent.
  • Nth-last-child selector (:nth-last-child(n)): Select all elements that are the n-th last child (1-based) of their respective parent.

Note: The way the Axis and Cursor types work, we cannot avoid matching the same node multiple times - this is mainly because there is no Eq instance for Cursor, and thus we cannot remove duplicate matches from the output of an Axis. For example, the element <div id="foo"/> would match twice on the selector div,#foo: once because it matches the element name "div", and once because it matches the ID "foo".

Depending on your needs, you may wish to either carefully design your selectors to avoid this, or to cull the results yourself, using a reasonable notion of equality.

Synopsis

Documentation

jq Source #

Arguments

:: (IsString (Tokens s), Stream s, Token s ~ Char) 
=> String

Name of source file

-> s

Input stream

-> Either (ParseErrorBundle s Text) Selector 

Parse from a stream, error information in Left on failure.

jqFile :: FilePath -> IO (Either (ParseErrorBundle Text Text) Selector) Source #

Parse from a file input stream, error information in Left on failure.

jqFile' :: FilePath -> IO Selector Source #

Parse from a file input stream, throw a UserError in IO on failure.

jqString Source #

Arguments

:: String

Input stream

-> Either (ParseErrorBundle String Text) Selector 

Parse from an unnamed String input stream, error information in Left on failure.

jqText Source #

Arguments

:: Text

Input stream

-> Either (ParseErrorBundle Text Text) Selector 

Parse from an unnamed Text input stream, error information in Left on failure.

jqString' Source #

Arguments

:: String

Input stream

-> Selector 

Parse from an unnamed String input stream, error on failure.

jqText' Source #

Arguments

:: Text

Input stream

-> Selector 

Parse from an unnamed Text input stream, error on failure.

errorBundlePretty #

Arguments

:: (VisualStream s, TraversableStream s, ShowErrorComponent e) 
=> ParseErrorBundle s e

Parse error bundle to display

-> String

Textual rendition of the bundle

Pretty-print a ParseErrorBundle. All ParseErrors in the bundle will be pretty-printed in order together with the corresponding offending lines by doing a single efficient pass over the input stream. The rendered String always ends with a newline.

Since: megaparsec-7.0.0

Orphan instances