Module genxml_counts

.

Copyright © 2024, Fred Youhanaie

Behaviours: gen_xml.

Authors: Fred Youhanaie (fyrlang@anydata.co.uk).

Description

A simple gen_xml callback module to count the tags.

The module will return count of the element tags found in the XML document.

The state variable for this handler should be a map. When calling read/2, it is recommended to supply an empty map as the initial value, i.e. #{}, although a map with preset values will not be rejected.

If a key for the Tag does not exist a new entry will be created. If a non-numeric entry exists for the Tag, the increment operation will cause an exception!

Function Index

handle_begin/3The callback function for begin tags.
handle_end/2The callback function for end tags.
handle_text/2The callback function for text elements.
start/1Helper function to scan an entire XML document.

Function Details

handle_begin/3

handle_begin(Tag::atom(), Attr::list(), Counts::map()) -> map()

The callback function for begin tags.

Each call increments the count for the corresponding Tag.

Everything else, such as attributes, end tags and text are ignored.

handle_end/2

handle_end(Tag::atom(), Counts::map()) -> map()

The callback function for end tags.

No action is performed with end tags.

handle_text/2

handle_text(Text::string(), Counts::map()) -> map()

The callback function for text elements.

No action is performed with these elements.

start/1

start(File::string()) -> gen_xml:read_ret()

Helper function to scan an entire XML document.


Generated by EDoc