libxml2: pattern.h File Reference

libxml2

Loading...
Searching...
No Matches
Typedefs | Enumerations | Functions
pattern.h File Reference

pattern expression handling More...

## Typedefs
typedef struct _xmlPattern | xmlPattern
| A compiled (XPath based) pattern to select nodes.
typedef struct _xmlStreamCtxt | xmlStreamCtxt
| State object for streaming interface.

## Enumerations
enum | xmlPatternFlags
| Internal type. More...

## Functions
void | xmlFreePattern (xmlPattern *comp)
| Free up the memory allocated by comp
void | xmlFreePatternList (xmlPattern *comp)
| Free up the memory allocated by all the elements of comp
xmlPattern * | xmlPatterncompile (const xmlChar *pattern, xmlDict *dict, int flags, const xmlChar **namespaces)
| Compile a pattern.
int | xmlPatternCompileSafe (const xmlChar *pattern, xmlDict *dict, int flags, const xmlChar **namespaces, xmlPattern **patternOut)
| Compile a pattern.
int | xmlPatternMatch (xmlPattern *comp, xmlNode *node)
| Test whether the node matches the pattern.
int | xmlPatternStreamable (xmlPattern *comp)
| Check if the pattern is streamable i.e.
int | xmlPatternMaxDepth (xmlPattern *comp)
| Check the maximum depth reachable by a pattern.
int | xmlPatternMinDepth (xmlPattern *comp)
| Check the minimum depth reachable by a pattern, 0 mean the / or .
int | xmlPatternFromRoot (xmlPattern *comp)
| Check if the pattern must be looked at from the root.
xmlStreamCtxt * | xmlPatternGetStreamCtxt (xmlPattern *comp)
| Get a streaming context for that pattern Use xmlFreeStreamCtxt to free the context.
void | xmlFreeStreamCtxt (xmlStreamCtxt *stream)
| Free the stream context.
int | xmlStreamPushNode (xmlStreamCtxt *stream, const xmlChar *name, const xmlChar *ns, int nodeType)
| Push new data onto the stream.
int | xmlStreamPush (xmlStreamCtxt *stream, const xmlChar *name, const xmlChar *ns)
| Push new data onto the stream.
int | xmlStreamPushAttr (xmlStreamCtxt *stream, const xmlChar *name, const xmlChar *ns)
| Push new attribute data onto the stream.
int | xmlStreamPop (xmlStreamCtxt *stream)
| push one level from the stream.
int | xmlStreamWantsAnyNode (xmlStreamCtxt *stream)
| Query if the streaming pattern additionally needs to be fed with text-, cdata-section-, comment- and processing-instruction-nodes.

## Detailed Description

pattern expression handling

allows to compile and test pattern expressions for nodes either in a tree or based on a parser state.

Copyright
  See Copyright for the status of this software.

Author
  Daniel Veillard

## Enumeration Type Documentation

## ◆ xmlPatternFlags

enum xmlPatternFlags

Internal type.

This is the set of options affecting the behaviour of pattern matching with this module.

## Function Documentation

## ◆ xmlFreePattern()

void xmlFreePattern | ( | xmlPattern * | comp | ) |

Free up the memory allocated by comp

Parameters

  comp | an XSLT comp

## ◆ xmlFreePatternList()

void xmlFreePatternList | ( | xmlPattern * | comp | ) |

Free up the memory allocated by all the elements of comp

Parameters

  comp | an XSLT comp list

## ◆ xmlFreeStreamCtxt()

void xmlFreeStreamCtxt | ( | xmlStreamCtxt * | stream | ) |

Free the stream context.

Parameters

  stream | the stream context

## ◆ xmlPatterncompile()

xmlPattern * xmlPatterncompile | ( | const xmlChar * | pattern,
|  | xmlDict * | dict,
|  | int | flags,
|  | const xmlChar ** | namespaces )

Compile a pattern.

Parameters

  pattern | the pattern to compile
  dict | an optional dictionary for interned strings
  flags | compilation flags, see xmlPatternFlags
  namespaces | the prefix definitions, array of [URI, prefix] or NULL

Returns
  the compiled form of the pattern or NULL in case of error

## ◆ xmlPatternCompileSafe()

int xmlPatternCompileSafe | ( | const xmlChar * | pattern,
|  | xmlDict * | dict,
|  | int | flags,
|  | const xmlChar ** | namespaces,
|  | xmlPattern ** | patternOut )

Compile a pattern.

Since
  2.13.0

Parameters

  pattern | the pattern to compile
  dict | an optional dictionary for interned strings
  flags | compilation flags, see xmlPatternFlags
  namespaces | the prefix definitions, array of [URI, prefix] or NULL
  patternOut | output pattern

Returns
  0 on success, 1 on error, -1 if a memory allocation failed.

## ◆ xmlPatternFromRoot()

int xmlPatternFromRoot | ( | xmlPattern * | comp | ) |

Check if the pattern must be looked at from the root.

Parameters

  comp | the precompiled pattern

Returns
  1 if true, 0 if false and -1 in case of error

## ◆ xmlPatternGetStreamCtxt()

xmlStreamCtxt * xmlPatternGetStreamCtxt | ( | xmlPattern * | comp | ) |

Get a streaming context for that pattern Use xmlFreeStreamCtxt to free the context.

Parameters

  comp | the precompiled pattern

Returns
  a pointer to the context or NULL in case of failure

## ◆ xmlPatternMatch()

int xmlPatternMatch | ( | xmlPattern * | comp,
|  | xmlNode * | node )

Test whether the node matches the pattern.

Parameters

  comp | the precompiled pattern
  node | a node

Returns
  1 if it matches, 0 if it doesn't and -1 in case of failure

## ◆ xmlPatternMaxDepth()

int xmlPatternMaxDepth | ( | xmlPattern * | comp | ) |

Check the maximum depth reachable by a pattern.

Parameters

  comp | the precompiled pattern

Returns
  -2 if no limit (using //), otherwise the depth, and -1 in case of error

## ◆ xmlPatternMinDepth()

int xmlPatternMinDepth | ( | xmlPattern * | comp | ) |

Check the minimum depth reachable by a pattern, 0 mean the / or .

are part of the set.

Parameters

  comp | the precompiled pattern

Returns
  -1 in case of error otherwise the depth,

## ◆ xmlPatternStreamable()

int xmlPatternStreamable | ( | xmlPattern * | comp | ) |

Check if the pattern is streamable i.e.

xmlPatternGetStreamCtxt should work.

Parameters

  comp | the precompiled pattern

Returns
  1 if streamable, 0 if not and -1 in case of error.

## ◆ xmlStreamPop()

int xmlStreamPop | ( | xmlStreamCtxt * | stream | ) |

push one level from the stream.

Parameters

  stream | the stream context

Returns
  -1 in case of error, 0 otherwise.

## ◆ xmlStreamPush()

int xmlStreamPush | ( | xmlStreamCtxt * | stream,
|  | const xmlChar * | name,
|  | const xmlChar * | ns )

Push new data onto the stream.

NOTE: if the call xmlPatterncompile indicated a dictionary, then strings for name and ns will be expected to come from the dictionary. Both name and ns being NULL means the / i.e. the root of the document. This can also act as a reset. Otherwise the function will act as if it has been given an element-node.

Parameters

  stream | the stream context
  name | the current name
  ns | the namespace name

Returns
  -1 in case of error, 1 if the current state in the stream is a match and 0 otherwise.

## ◆ xmlStreamPushAttr()

int xmlStreamPushAttr | ( | xmlStreamCtxt * | stream,
|  | const xmlChar * | name,
|  | const xmlChar * | ns )

Push new attribute data onto the stream.

NOTE: If the call to xmlPatterncompile indicated a dictionary, then strings for name and ns will be expected to come from the dictionary.

Both name and ns being NULL means the root of the document. This can also act as a reset. Otherwise the function will act as if it has been given an attribute-node.

Parameters

  stream | the stream context
  name | the current name
  ns | the namespace name

Returns
  -1 in case of error, 1 if the current state in the stream is a match and 0 otherwise.

## ◆ xmlStreamPushNode()

int xmlStreamPushNode | ( | xmlStreamCtxt * | stream,
|  | const xmlChar * | name,
|  | const xmlChar * | ns,
|  | int | nodeType )

Push new data onto the stream.

NOTE: if the call xmlPatterncompile indicated a dictionary, then strings for name and ns will be expected to come from the dictionary. Both name and ns being NULL means the / i.e. the root of the document. This can also act as a reset. Different from xmlStreamPush this function can be fed with nodes of type: element-, attribute-, text-, cdata-section-, comment- and processing-instruction-node.

Parameters

  stream | the stream context
  name | the current name
  ns | the namespace name
  nodeType | the type of the node being pushed

Returns
  -1 in case of error, 1 if the current state in the stream is a match and 0 otherwise.

## ◆ xmlStreamWantsAnyNode()

int xmlStreamWantsAnyNode | ( | xmlStreamCtxt * | streamCtxt | ) |

Query if the streaming pattern additionally needs to be fed with text-, cdata-section-, comment- and processing-instruction-nodes.

If the result is 0 then only element-nodes and attribute-nodes need to be pushed.

Parameters

  streamCtxt | the stream context

Returns
  1 in case of need of nodes of the above described types, 0 otherwise. -1 on API errors.