UTILLib 2.0
Common C++ library with utilities.
Loading...
Searching...
No Matches
util::xml::IXmlFile Class Reference

Interface class that defines an XML parser. More...

#include "util/ixmlfile.h"

Public Member Functions

virtual ~IXmlFile ()=default
 Destructor.
void FileName (const std::string &filename)
 Sets the file name (full path).
std::string FileName () const
 Return the full path file name.
std::string FileNameWithoutPath () const
 File name without path.
std::string Version () const
 Returns the XML file version.
void Version (const std::string &version)
 Sets the version of the XML file.
std::string Encoding () const
 Return the character encoding of the XML file.
void Encoding (const std::string &encoding)
 Sets the XML file encoding.
bool Standalone () const
 Returns true is the XML file is stand-alone.
std::string RootName () const
 Returns the name of the root tag.
IXmlNodeRootName (const std::string &name)
 Create the root tag in an XML file object.
IXmlNodeRootNode () const
 Returns the root node in XML file.
std::string StyleSheet () const
 Returns the used style sheet.
void StyleSheet (const std::string &style_sheet)
 Sets the style sheet.
template<typename T>
Property (const std::string &key, const T &def={}) const
 Returns an XML tags value.
template<typename T>
void SetProperty (const std::string &key, const T &value)
 Sets a property tag value.
void GetChildList (IXmlNode::ChildList &child_list) const
 Returns a list of child tags below the root tag.
const IXmlNodeGetNode (const std::string &tag) const
 Returns a node with a tag name.
virtual bool ParseFile ()
 Parses the XML file.
virtual bool ParseString (const std::string &input)
 Parses a string instead of a file.
virtual void Reset ()
 Reset the internals i.e. ready for a new parsing.
virtual bool WriteFile ()
 Writes the XML file.
std::string WriteString (bool skip_header=false)

Protected Member Functions

 IXmlFile ()=default
 Default constructor is hidden from external users.
virtual std::unique_ptr< IXmlNodeCreateNode (const std::string &name)
 Creates a new node.

Protected Attributes

std::string filename_
 File name with full path.
std::string version_ = "1.0"
 Version of the XML file.
std::string encoding_ = "UTF-8"
 Encoding of strings in the XML file.
std::string style_sheet_
 Optional style sheet.
bool standalone_ = true
 True of the file is standalone.
std::unique_ptr< IXmlNoderoot_node_
 Pointer to the root node.

Detailed Description

The interface shall hide the implementation code of an XML parser.

Member Function Documentation

◆ Encoding() [1/2]

std::string util::xml::IXmlFile::Encoding ( ) const
inlinenodiscard

Returns the character encoding of the XML file. Standard encoding is UTF-8.

Returns
XML encoding.

◆ Encoding() [2/2]

void util::xml::IXmlFile::Encoding ( const std::string & encoding)
inline

Sets the XML file encoding. By default the UTF-8 encoding is used.

Parameters
encodingXML file encoding

◆ FileName() [1/2]

std::string util::xml::IXmlFile::FileName ( ) const
inlinenodiscard
Returns
Full path to the file name

◆ FileName() [2/2]

void util::xml::IXmlFile::FileName ( const std::string & filename)
Parameters
filenameFile name with full path

◆ GetChildList()

void util::xml::IXmlFile::GetChildList ( IXmlNode::ChildList & child_list) const

Returns a list of tags below the root tag.

Parameters
child_listList of main tags in the file, Returns a list of XML tags (nodes).

◆ GetNode()

const IXmlNode * util::xml::IXmlFile::GetNode ( const std::string & tag) const
nodiscard

Returns a (unique) node with a specific tag name

Parameters
tagTag name
Returns
Pointer ti the node. Returns a tag node.

◆ Property()

template<typename T>
T util::xml::IXmlFile::Property ( const std::string & key,
const T & def = {} ) const
inlinenodiscard

Returns a value of an XML tag excluding the root tag.

Template Parameters
TType can be string, numbers and boolean.
Parameters
[in]keyTag name with the value.
[in]defDefault value if not found.
Returns
Returns the tag value or default value.

◆ RootName() [1/2]

std::string util::xml::IXmlFile::RootName ( ) const
inlinenodiscard
Returns
Name of the root tag

< Return the name of the root tag.

◆ RootName() [2/2]

IXmlNode & util::xml::IXmlFile::RootName ( const std::string & name)

Creates the root tag and sets its tag name.

Parameters
nameName of the root tag

◆ RootNode()

IXmlNode * util::xml::IXmlFile::RootNode ( ) const
inlinenodiscard

Returns the root node in the XML file. Note that this function may return null if no root node exist,

Returns
The root node object if it exists, otherwise null.

◆ SetProperty()

template<typename T>
void util::xml::IXmlFile::SetProperty ( const std::string & key,
const T & value )
inline

Sets a property tag value

Template Parameters
TType of value
Parameters
keyTag name
valueTag value

◆ Standalone()

bool util::xml::IXmlFile::Standalone ( ) const
inlinenodiscard
Returns
True if the XML file is stand-alone.

◆ StyleSheet() [1/2]

std::string util::xml::IXmlFile::StyleSheet ( ) const
inlinenodiscard

Returns the used style sheet.

Returns
The style sheet

◆ StyleSheet() [2/2]

void util::xml::IXmlFile::StyleSheet ( const std::string & style_sheet)
inline

Sets the style sheet. Include full url path.

Parameters
style_sheetURL to style sheet.

◆ Version() [1/2]

std::string util::xml::IXmlFile::Version ( ) const
inlinenodiscard

Returns the XML file version. Typical 1.0 or 1.1.

Returns
XML version.

◆ Version() [2/2]

void util::xml::IXmlFile::Version ( const std::string & version)
inline

Sets the XML file version. Set default to 1.0.

Parameters
versionXML version.

◆ WriteString()

std::string util::xml::IXmlFile::WriteString ( bool skip_header = false)

Creates a string that is a whole XML file.


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