DocWire SDK
DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, document analysis. Offline processing possible for security and confidentiality
docwire::xml::reader< safety_level > Class Template Reference

A forward-only, non-cached XML reader. More...

#include <xml_reader.h>

Inheritance diagram for docwire::xml::reader< safety_level >:
docwire::with_pimpl< reader< default_safety_level > > docwire::with_pimpl_base

Public Member Functions

 reader (std::string_view xml_sv, reader_blanks blanks_option=reader_blanks::keep)
 Constructs a reader from a string view. More...
 
bool read_next () const
 Advances the reader to the next node. More...
 
std::string_view content () const
 Returns the content of the current node (e.g., text inside an element).
 
std::string_view name () const
 Returns the local name of the current node.
 
std::string_view full_name () const
 Returns the full name (including namespace) of the current node.
 
std::string_view string_value () const
 Returns the string value of the current node (concatenated text of children).
 
bool move_to_first_attribute () const
 Moves the reader to the first attribute of the current element. More...
 
bool move_to_next_attribute () const
 Moves the reader to the next attribute. More...
 
void move_to_element () const noexcept(safety_level==relaxed)
 Moves the reader back to the element containing the attributes. More...
 
non_negative< int, safety_level > depth () const
 Returns the depth of the current node in the XML tree.
 
node_type type () const
 Returns the type of the current node.
 

Additional Inherited Members

- Protected Types inherited from docwire::with_pimpl< reader< default_safety_level > >
using impl_type = pimpl_impl< reader< default_safety_level > >
 
- Protected Member Functions inherited from docwire::with_pimpl< reader< default_safety_level > >
impl_typecreate_impl (Args &&... args)
 
 with_pimpl (Args &&... args)
 
 with_pimpl (with_pimpl< reader< default_safety_level > > &&other) noexcept
 
 with_pimpl (std::nullptr_t)
 
with_pimploperator= (with_pimpl &&other) noexcept
 
impl_typeimpl ()
 
const impl_typeimpl () const
 

Detailed Description

template<safety_policy safety_level = default_safety_level>
class docwire::xml::reader< safety_level >

A forward-only, non-cached XML reader.

This class provides a wrapper around libxml2's xmlTextReader, offering a modern C++ interface with configurable safety policies.

Template Parameters
safety_levelThe safety policy to use (strict or relaxed).
Warning
This is a single-pass reader. Once the reader advances, previous nodes cannot be revisited.
See also
XML parsing example

Definition at line 63 of file xml_reader.h.

Constructor & Destructor Documentation

◆ reader()

template<safety_policy safety_level = default_safety_level>
docwire::xml::reader< safety_level >::reader ( std::string_view  xml_sv,
reader_blanks  blanks_option = reader_blanks::keep 
)
explicit

Constructs a reader from a string view.

Parameters
xml_svThe XML content to parse.
blanks_optionSpecifies whether to keep or ignore blank nodes (default: keep).

Member Function Documentation

◆ move_to_element()

template<safety_policy safety_level = default_safety_level>
void docwire::xml::reader< safety_level >::move_to_element ( ) const
noexcept

Moves the reader back to the element containing the attributes.

Exceptions
docwire::errorIn strict mode, throws if the operation fails (e.g., reader is not positioned on an attribute).

◆ move_to_first_attribute()

template<safety_policy safety_level = default_safety_level>
bool docwire::xml::reader< safety_level >::move_to_first_attribute ( ) const

Moves the reader to the first attribute of the current element.

Returns
true if successful, false if no attributes exist.

◆ move_to_next_attribute()

template<safety_policy safety_level = default_safety_level>
bool docwire::xml::reader< safety_level >::move_to_next_attribute ( ) const

Moves the reader to the next attribute.

Returns
true if successful, false if no more attributes exist.

◆ read_next()

template<safety_policy safety_level = default_safety_level>
bool docwire::xml::reader< safety_level >::read_next ( ) const

Advances the reader to the next node.

Returns
true if a node was read, false if the end of the document was reached.

The documentation for this class was generated from the following file: