libxml++  4.9.1
About: libxml++ is a C++ wrapper for the libxml XML parser library.
  Fossies Dox: libxml++-4.9.1.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

xmlpp::TextReader Class Reference

A TextReader-style XML parser. More...

#include <textreader.h>

Inheritance diagram for xmlpp::TextReader:
[legend]
Collaboration diagram for xmlpp::TextReader:
[legend]

Classes

class  PropertyReader
 

Public Types

enum  NodeType {
  NodeType::InternalError = -1, NodeType::None = 0, NodeType::Element = 1, NodeType::Attribute = 2,
  NodeType::Text = 3, NodeType::CDATA = 4, NodeType::EntityReference = 5, NodeType::Entity = 6,
  NodeType::ProcessingInstruction = 7, NodeType::Comment = 8, NodeType::Document = 9, NodeType::DocumentType = 10,
  NodeType::DocumentFragment = 11, NodeType::Notation = 12, NodeType::Whitespace = 13, NodeType::SignificantWhitespace = 14,
  NodeType::EndElement = 15, NodeType::EndEntity = 16, NodeType::XmlDeclaration = 17
}
 Node type of the current node. More...
 
enum  ReadState {
  ReadState::InternalError = -1, ReadState::Initial = 0, ReadState::Interactive = 1, ReadState::Error = 2,
  ReadState::EndOfFile = 3, ReadState::Closed = 4, ReadState::Reading = 5
}
 
enum  ParserProperties { ParserProperties::LoadDtd = 1, ParserProperties::DefaultAttrs = 2, ParserProperties::Validate = 3, ParserProperties::SubstEntities = 4 }
 
using size_type = unsigned int
 

Public Member Functions

 TextReader (struct _xmlTextReader *cobj)
 Wraps a TextReader object from an underlying libxml object. More...
 
 TextReader (const ustring &URI)
 Creates a new TextReader object to parse a file or URI. More...
 
 TextReader (const unsigned char *data, size_type size, const ustring &uri=ustring())
 Creates a new TextReader object which parses in memory data. More...
 
 ~TextReader () override
 
bool read ()
 Moves the position of the current instance to the next node in the stream, exposing its properties. More...
 
ustring read_inner_xml ()
 Reads the contents of the current node, including child nodes and markup. More...
 
ustring read_outer_xml ()
 Reads the current node and its contents, including child nodes and markup. More...
 
ustring read_string ()
 Reads the contents of an element or a text node as a string. More...
 
bool read_attribute_value ()
 Parses an attribute value into one or more Text and EntityReference nodes. More...
 
int get_attribute_count () const
 Gets the number of attributes on the current node. More...
 
ustring get_base_uri () const
 Gets the base Uniform Resource Identifier (URI) of the current node. More...
 
int get_depth () const
 Gets the depth of the current node in the XML document. More...
 
bool has_attributes () const
 Gets a value indicating whether the current node has any attributes. More...
 
bool has_value () const
 Whether the node can have a text value. More...
 
bool is_default () const
 Whether an Attribute node was generated from the default value defined in the DTD or schema. More...
 
bool is_empty_element () const
 Check if the current node is empty. More...
 
ustring get_local_name () const
 
ustring get_name () const
 
ustring get_namespace_uri () const
 
NodeType get_node_type () const
 Get the node type of the current node. More...
 
ustring get_prefix () const
 Get the namespace prefix associated with the current node. More...
 
char get_quote_char () const
 Get the quotation mark character used to enclose the value of an attribute. More...
 
ustring get_value () const
 
ustring get_xml_lang () const
 
ReadState get_read_state () const
 
void close ()
 
ustring get_attribute (int number) const
 
ustring get_attribute (const ustring &name) const
 
ustring get_attribute (const ustring &local_name, const ustring &ns_uri) const
 
ustring lookup_namespace (const ustring &prefix) const
 
bool move_to_attribute (int number)
 
bool move_to_attribute (const ustring &name)
 
bool move_to_attribute (const ustring &local_name, const ustring &ns_uri)
 
bool move_to_first_attribute ()
 
bool move_to_next_attribute ()
 
bool move_to_element ()
 
bool get_normalization () const
 
void set_normalization (bool value)
 
bool get_parser_property (ParserProperties property) const
 
void set_parser_property (ParserProperties property, bool value)
 
Nodeget_current_node ()
 Get a pointer to the current node. More...
 
const Nodeget_current_node () const
 Get a pointer to the current node. More...
 
Nodeexpand ()
 Expand the current node. More...
 
bool next ()
 
bool is_valid () const
 

Private Member Functions

void setup_exceptions ()
 
void check_for_exceptions () const
 

Static Private Member Functions

static void on_libxml_error (void *arg, const char *msg, int severity, void *locator)
 

Private Attributes

std::unique_ptr< PropertyReaderpropertyreader
 
_xmlTextReader * impl_
 
int severity_
 
ustring error_
 

Friends

class PropertyReader
 

Additional Inherited Members

- Protected Member Functions inherited from xmlpp::NonCopyable
 NonCopyable () noexcept
 
virtual ~NonCopyable ()
 
 NonCopyable (const NonCopyable &)=delete
 
NonCopyableoperator= (const NonCopyable &)=delete
 
 NonCopyable (NonCopyable &&)=delete
 
NonCopyableoperator= (NonCopyable &&)=delete
 

Detailed Description

A TextReader-style XML parser.

A reader that provides fast, non-cached, forward-only access to XML data, in the style of .Net's XmlTextReader class.

Definition at line 29 of file textreader.h.

Member Typedef Documentation

◆ size_type

using xmlpp::TextReader::size_type = unsigned int

Definition at line 80 of file textreader.h.

Member Enumeration Documentation

◆ NodeType

Node type of the current node.

See DotGNU's XmlNodeType enum.

Enumerator
InternalError 
None 
Element 
Attribute 
Text 
CDATA 
EntityReference 
Entity 
ProcessingInstruction 
Comment 
Document 
DocumentType 
DocumentFragment 
Notation 
Whitespace 
SignificantWhitespace 
EndElement 
EndEntity 
XmlDeclaration 

Definition at line 36 of file textreader.h.

◆ ParserProperties

Enumerator
LoadDtd 
DefaultAttrs 
Validate 
SubstEntities 

Definition at line 72 of file textreader.h.

◆ ReadState

Enumerator
InternalError 
Initial 
Interactive 
Error 
EndOfFile 
Closed 
Reading 

Definition at line 60 of file textreader.h.

Constructor & Destructor Documentation

◆ TextReader() [1/3]

xmlpp::TextReader::TextReader ( struct _xmlTextReader *  cobj)

Wraps a TextReader object from an underlying libxml object.

The TextReader takes ownership of cobj.

Parameters
cobjThe underlying libxml xmlTextReader object.

Definition at line 28 of file textreader.cc.

References setup_exceptions().

◆ TextReader() [2/3]

xmlpp::TextReader::TextReader ( const ustring URI)

Creates a new TextReader object to parse a file or URI.

Parameters
URIThe URI to read.
Exceptions
xmlpp::internal_errorIf an xmlTextReader object cannot be created.

Definition at line 52 of file textreader.cc.

References impl_, and setup_exceptions().

◆ TextReader() [3/3]

xmlpp::TextReader::TextReader ( const unsigned char *  data,
size_type  size,
const ustring uri = ustring() 
)

Creates a new TextReader object which parses in memory data.

Parameters
dataThe data to parse.
sizeThe number of bytes in data.
uriThe base URI to use for the document.
Exceptions
xmlpp::internal_errorIf an xmlTextReader object cannot be created.

Definition at line 36 of file textreader.cc.

References impl_, and setup_exceptions().

◆ ~TextReader()

xmlpp::TextReader::~TextReader ( )
override

Definition at line 65 of file textreader.cc.

References impl_.

Member Function Documentation

◆ check_for_exceptions()

void xmlpp::TextReader::check_for_exceptions ( ) const
private

◆ close()

void xmlpp::TextReader::close ( )

Definition at line 200 of file textreader.cc.

References check_for_exceptions(), and impl_.

◆ expand()

Node * xmlpp::TextReader::expand ( )

Expand the current node.

Reads the contents of the current node and the full subtree. It then makes the subtree available until the next call to read() or next().

Warning
The C++ wrappers are not deleted. Using this method causes memory leaks, unless you call xmlpp::Node::free_wrappers(), which is not intended to be called by the application.
Returns
A pointer to the current node, or nullptr in case of error.
Exceptions
xmlpp::parse_error
xmlpp::validity_error

Definition at line 322 of file textreader.cc.

References check_for_exceptions(), xmlpp::Node::create_wrapper(), and impl_.

◆ get_attribute() [1/3]

ustring xmlpp::TextReader::get_attribute ( const ustring local_name,
const ustring ns_uri 
) const

Definition at line 219 of file textreader.cc.

References impl_, and propertyreader.

◆ get_attribute() [2/3]

ustring xmlpp::TextReader::get_attribute ( const ustring name) const

Definition at line 212 of file textreader.cc.

References impl_, and propertyreader.

◆ get_attribute() [3/3]

ustring xmlpp::TextReader::get_attribute ( int  number) const

Definition at line 206 of file textreader.cc.

References impl_, and propertyreader.

◆ get_attribute_count()

int xmlpp::TextReader::get_attribute_count ( ) const

Gets the number of attributes on the current node.

Returns
The number of attributes on the current node, or zero if the current node does not support attributes, or -1 in case of error.
Exceptions
xmlpp::parse_error
xmlpp::validity_error

Definition at line 100 of file textreader.cc.

References impl_, and propertyreader.

◆ get_base_uri()

ustring xmlpp::TextReader::get_base_uri ( ) const

Gets the base Uniform Resource Identifier (URI) of the current node.

Returns
The base URI of the current node or an empty ustring if not available.

Definition at line 106 of file textreader.cc.

References impl_, and propertyreader.

◆ get_current_node() [1/2]

Node * xmlpp::TextReader::get_current_node ( )

Get a pointer to the current node.

Warning
This is dangerous because the underlying node may be destroyed on the next read. The C++ wrapper is not deleted. Using this method causes memory leaks, unless you call xmlpp::Node::free_wrappers(), which is not intended to be called by the application.
Returns
A pointer to the current node, or nullptr in case of error.

Definition at line 294 of file textreader.cc.

References check_for_exceptions(), xmlpp::Node::create_wrapper(), and impl_.

Referenced by get_current_node().

◆ get_current_node() [2/2]

const Node * xmlpp::TextReader::get_current_node ( ) const

Get a pointer to the current node.

Warning
See the non-const get_current_node().
Returns
A pointer to the current node, or nullptr in case of error.

Definition at line 307 of file textreader.cc.

References get_current_node().

◆ get_depth()

int xmlpp::TextReader::get_depth ( ) const

Gets the depth of the current node in the XML document.

Returns
The depth of the current node in the XML document, or -1 in case of error.

Definition at line 112 of file textreader.cc.

References impl_, and propertyreader.

◆ get_local_name()

ustring xmlpp::TextReader::get_local_name ( ) const

Definition at line 142 of file textreader.cc.

References impl_, and propertyreader.

◆ get_name()

ustring xmlpp::TextReader::get_name ( ) const

Definition at line 148 of file textreader.cc.

References impl_, and propertyreader.

◆ get_namespace_uri()

ustring xmlpp::TextReader::get_namespace_uri ( ) const

Definition at line 154 of file textreader.cc.

References impl_, and propertyreader.

◆ get_node_type()

TextReader::NodeType xmlpp::TextReader::get_node_type ( ) const

Get the node type of the current node.

Returns
The xmlpp::TextReader::NodeType of the current node. In case of error, either returns xmlpp::TextReader::NodeType::InternalError or throws an exception.
Exceptions
xmlpp::parse_error
xmlpp::validity_error

Definition at line 160 of file textreader.cc.

References check_for_exceptions(), and impl_.

◆ get_normalization()

bool xmlpp::TextReader::get_normalization ( ) const

Definition at line 273 of file textreader.cc.

References impl_, and propertyreader.

◆ get_parser_property()

bool xmlpp::TextReader::get_parser_property ( ParserProperties  property) const

Definition at line 279 of file textreader.cc.

References impl_, and propertyreader.

◆ get_prefix()

ustring xmlpp::TextReader::get_prefix ( ) const

Get the namespace prefix associated with the current node.

Returns
The namespace prefix, or an empty string if not available.

Definition at line 168 of file textreader.cc.

References impl_, and propertyreader.

◆ get_quote_char()

char xmlpp::TextReader::get_quote_char ( ) const

Get the quotation mark character used to enclose the value of an attribute.

Returns
Returns " or ' and -1 in case of error.

Definition at line 174 of file textreader.cc.

References impl_, and propertyreader.

◆ get_read_state()

TextReader::ReadState xmlpp::TextReader::get_read_state ( ) const

Definition at line 192 of file textreader.cc.

References check_for_exceptions(), and impl_.

◆ get_value()

ustring xmlpp::TextReader::get_value ( ) const

Definition at line 180 of file textreader.cc.

References impl_, and propertyreader.

◆ get_xml_lang()

ustring xmlpp::TextReader::get_xml_lang ( ) const

Definition at line 186 of file textreader.cc.

References impl_, and propertyreader.

◆ has_attributes()

bool xmlpp::TextReader::has_attributes ( ) const

Gets a value indicating whether the current node has any attributes.

Returns
true if the current has attributes, false otherwise.

Definition at line 118 of file textreader.cc.

References impl_, and propertyreader.

◆ has_value()

bool xmlpp::TextReader::has_value ( ) const

Whether the node can have a text value.

Returns
true if the current node can have an associated text value, false otherwise.

Definition at line 124 of file textreader.cc.

References impl_, and propertyreader.

◆ is_default()

bool xmlpp::TextReader::is_default ( ) const

Whether an Attribute node was generated from the default value defined in the DTD or schema.

Returns
true if defaulted, false otherwise.

Definition at line 130 of file textreader.cc.

References impl_, and propertyreader.

◆ is_empty_element()

bool xmlpp::TextReader::is_empty_element ( ) const

Check if the current node is empty.

Returns
true if empty, false otherwise.

Definition at line 136 of file textreader.cc.

References impl_, and propertyreader.

◆ is_valid()

bool xmlpp::TextReader::is_valid ( ) const

Definition at line 341 of file textreader.cc.

References impl_, and propertyreader.

◆ lookup_namespace()

ustring xmlpp::TextReader::lookup_namespace ( const ustring prefix) const

Definition at line 227 of file textreader.cc.

References impl_, and propertyreader.

◆ move_to_attribute() [1/3]

bool xmlpp::TextReader::move_to_attribute ( const ustring local_name,
const ustring ns_uri 
)

Definition at line 247 of file textreader.cc.

References impl_, and propertyreader.

◆ move_to_attribute() [2/3]

bool xmlpp::TextReader::move_to_attribute ( const ustring name)

Definition at line 240 of file textreader.cc.

References impl_, and propertyreader.

◆ move_to_attribute() [3/3]

bool xmlpp::TextReader::move_to_attribute ( int  number)

Definition at line 234 of file textreader.cc.

References impl_, and propertyreader.

◆ move_to_element()

bool xmlpp::TextReader::move_to_element ( )

Definition at line 267 of file textreader.cc.

References impl_, and propertyreader.

◆ move_to_first_attribute()

bool xmlpp::TextReader::move_to_first_attribute ( )

Definition at line 255 of file textreader.cc.

References impl_, and propertyreader.

◆ move_to_next_attribute()

bool xmlpp::TextReader::move_to_next_attribute ( )

Definition at line 261 of file textreader.cc.

References impl_, and propertyreader.

◆ next()

bool xmlpp::TextReader::next ( )

Definition at line 335 of file textreader.cc.

References impl_, and propertyreader.

◆ on_libxml_error()

void xmlpp::TextReader::on_libxml_error ( void *  arg,
const char *  msg,
int  severity,
void *  locator 
)
staticprivate

Definition at line 361 of file textreader.cc.

References severity_.

Referenced by setup_exceptions().

◆ read()

bool xmlpp::TextReader::read ( )

Moves the position of the current instance to the next node in the stream, exposing its properties.

Returns
true if the node was read successfully, false if there are no more nodes to read.
Exceptions
xmlpp::parse_error
xmlpp::validity_error

Definition at line 70 of file textreader.cc.

References impl_, and propertyreader.

◆ read_attribute_value()

bool xmlpp::TextReader::read_attribute_value ( )

Parses an attribute value into one or more Text and EntityReference nodes.

Returns
A bool where true indicates the attribute value was parsed, and false indicates the reader was not positioned on an attribute node or all the attribute values have been read.
Exceptions
xmlpp::parse_error
xmlpp::validity_error

Definition at line 94 of file textreader.cc.

References impl_, and propertyreader.

◆ read_inner_xml()

ustring xmlpp::TextReader::read_inner_xml ( )

Reads the contents of the current node, including child nodes and markup.

Returns
A ustring containing the XML content, or an empty ustring if the current node is neither an element nor attribute, or has no child nodes.
Exceptions
xmlpp::parse_error
xmlpp::validity_error

Definition at line 76 of file textreader.cc.

References impl_, and propertyreader.

◆ read_outer_xml()

ustring xmlpp::TextReader::read_outer_xml ( )

Reads the current node and its contents, including child nodes and markup.

Returns
A ustring containing the XML content, or an empty ustring if the current node is neither an element nor attribute.
Exceptions
xmlpp::parse_error
xmlpp::validity_error

Definition at line 82 of file textreader.cc.

References impl_, and propertyreader.

◆ read_string()

ustring xmlpp::TextReader::read_string ( )

Reads the contents of an element or a text node as a string.

Returns
A ustring containing the contents of the Element or Text node, or an empty ustring if the reader is positioned on any other type of node.
Exceptions
xmlpp::parse_error
xmlpp::validity_error

Definition at line 88 of file textreader.cc.

References impl_, and propertyreader.

◆ set_normalization()

void xmlpp::TextReader::set_normalization ( bool  value)

◆ set_parser_property()

void xmlpp::TextReader::set_parser_property ( ParserProperties  property,
bool  value 
)

Definition at line 286 of file textreader.cc.

References check_for_exceptions(), and impl_.

◆ setup_exceptions()

void xmlpp::TextReader::setup_exceptions ( )
private

Definition at line 347 of file textreader.cc.

References impl_, and on_libxml_error().

Referenced by TextReader().

Friends And Related Function Documentation

◆ PropertyReader

friend class PropertyReader
friend

Definition at line 266 of file textreader.h.

Member Data Documentation

◆ error_

ustring xmlpp::TextReader::error_
private

Definition at line 276 of file textreader.h.

Referenced by check_for_exceptions().

◆ impl_

◆ propertyreader

◆ severity_

int xmlpp::TextReader::severity_
private

Definition at line 275 of file textreader.h.

Referenced by check_for_exceptions(), and on_libxml_error().


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