atomicrex  0.1
An advanced atomistic model building tool
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
atomicrex::XML::Element Class Reference

#include <XMLUtilities.h>

Inheritance diagram for atomicrex::XML::Element:
atomicrex::XML::OElement

Public Member Functions

 Element (xmlNodePtr e=nullptr)
 Constructor that takes a LibXml element.
 
FPString textContent () const
 Returns the text content of the XML element.
 
int parseIntParameterElement (const char *tagName) const
 
int parseOptionalIntParameterElement (const char *tagName, int defaultValue) const
 
double parseFloatParameterElement (const char *tagName) const
 
double parseOptionalFloatParameterElement (const char *tagName, double defaultValue) const
 
FPString parseStringParameterElement (const char *tagName) const
 
FPString parseOptionalStringParameterElement (const char *tagName, const FPString &defaultValue=FPString()) const
 
FPString parsePathParameterElement (const char *tagName) const
 
FPString parseOptionalPathParameterElement (const char *tagName, const FPString &defaultValue=FPString()) const
 
double parseFloatParameterAttribute (const char *attributeName) const
 
double parseOptionalFloatParameterAttribute (const char *attributeName, double defaultValue) const
 
int parseIntParameterAttribute (const char *attributeName) const
 
int parseOptionalIntParameterAttribute (const char *attributeName, int defaultValue) const
 
FPString parseStringParameterAttribute (const char *attributeName) const
 
FPString parseOptionalStringParameterAttribute (const char *attributeName, const FPString &defaultValue=FPString()) const
 
FPString parsePathParameterAttribute (const char *attributeName) const
 
bool parseBooleanParameterAttribute (const char *attributeName) const
 
bool parseOptionalBooleanParameterAttribute (const char *attributeName, bool defaultValue) const
 
Element firstChildElement () const
 Returns the element's first child element if it has any.
 
Element firstChildElement (const char *tagName) const
 Returns the first child element with the given tag name if it has any.
 
Element expectChildElement (const char *tagName) const
 Returns the first child element with the given name, or throws an exception if it doesn't exist.
 
 operator bool () const noexcept
 Returns whether this element object is null (i.e. not pointing to any XML element).
 
bool tagEquals (const char *tagName) const
 Returns true if this element's tag name equals the given string.
 
void expectTag (const char *tagName) const
 Throws an exception if the element' tag doesn't equal the given string.
 
bool hasAttribute (const char *attrName) const
 Returns true if this XML element has an attribute with the given name.
 
int lineNumber () const
 Returns the line number of this element in the XML file.
 
Element nextSibling () const
 Returns the next sibling element from the children of this element's parent element.
 
Element nextSibling (const char *tagName) const
 Returns the next sibling element with the given tag name from the children of this element's parent element.
 
const char * tag () const
 Returns the tag name of this element.
 
 operator xmlNodePtr () const noexcept
 Returns the wrapped libxml element.
 
Element createIntParameterElement (const char *tagName, int value)
 Creates a child element with formatted text content.
 
Element createFloatParameterElement (const char *tagName, double value)
 Creates a child element with formatted text content.
 
Element createStringParameterElement (const char *tagName, const FPString &value)
 Creates a child element with formatted text content.
 
int attributeCount () const
 Returns the number of attributes of this element.
 
void appendChild (OElement &element)
 Appends a child element to this element.
 
void appendChild (OElement &&element)
 Appends a child element to this element.
 
void setAttribute (const char *attr, const FPString &value)
 Sets an attribute on this XML element.
 
void setTagName (const FPString &tagName)
 Changes the tag name of this element.
 
void setTextContent (const FPString &text)
 

Protected Member Functions

FPString resolveFilename (const FPString &filename) const
 

Protected Attributes

xmlNodePtr _el
 The internal pointer to the xmllib element.
 

Detailed Description

An input XML element from the DOM tree model used for file parsing.

This is a thin wrapper class for elements of the LibXML library.

Member Function Documentation

◆ parseBooleanParameterAttribute()

bool atomicrex::XML::Element::parseBooleanParameterAttribute ( const char *  attributeName) const

Parses a single boolean parameter from an XML element attribute. Throws an exception if attribute doesn't exist.

◆ parseFloatParameterAttribute()

double atomicrex::XML::Element::parseFloatParameterAttribute ( const char *  attributeName) const

Parses a single float parameter from an attribute of the element. Throws an exception if attribute doesn't exist.

◆ parseFloatParameterElement()

double atomicrex::XML::Element::parseFloatParameterElement ( const char *  tagName) const

Parses a single float parameter from a child element. Throws an exception if child element doesn't exist.

◆ parseIntParameterAttribute()

int atomicrex::XML::Element::parseIntParameterAttribute ( const char *  attributeName) const

Parses a single integer parameter from an XML element attribute. Throws an exception if attribute doesn't exist.

◆ parseIntParameterElement()

int atomicrex::XML::Element::parseIntParameterElement ( const char *  tagName) const

Parses a single integer parameter from a child element with the given name. Throws an exception if child element doesn't exist.

◆ parseOptionalBooleanParameterAttribute()

bool atomicrex::XML::Element::parseOptionalBooleanParameterAttribute ( const char *  attributeName,
bool  defaultValue 
) const

Parses a single boolean parameter from an XML element attribute if present. Returns the provided default value if attribute doesn't exist.

◆ parseOptionalFloatParameterAttribute()

double atomicrex::XML::Element::parseOptionalFloatParameterAttribute ( const char *  attributeName,
double  defaultValue 
) const

Parses a single float parameter from an XML element attribute if present. Returns the provided default value if attribute doesn't exist.

◆ parseOptionalFloatParameterElement()

double atomicrex::XML::Element::parseOptionalFloatParameterElement ( const char *  tagName,
double  defaultValue 
) const

Parses a single float parameter from a child element. Returns the provided default value if child element doesn't exist.

◆ parseOptionalIntParameterAttribute()

int atomicrex::XML::Element::parseOptionalIntParameterAttribute ( const char *  attributeName,
int  defaultValue 
) const

Parses a single integer parameter from an XML element attribute if present. Returns the provided default value if attribute doesn't exist.

◆ parseOptionalIntParameterElement()

int atomicrex::XML::Element::parseOptionalIntParameterElement ( const char *  tagName,
int  defaultValue 
) const

Parses a single integer parameter from a child element. Returns the provided default value if child element doesn't exist.

◆ parseOptionalPathParameterElement()

FPString atomicrex::XML::Element::parseOptionalPathParameterElement ( const char *  tagName,
const FPString defaultValue = FPString() 
) const

Parses a file path from a child element. Returns the provided default value if child element doesn't exist.

◆ parseOptionalStringParameterAttribute()

FPString atomicrex::XML::Element::parseOptionalStringParameterAttribute ( const char *  attributeName,
const FPString defaultValue = FPString() 
) const

Parses a single string parameter from an XML element attribute if present. Returns the provided default value if attribute doesn't exist.

◆ parseOptionalStringParameterElement()

FPString atomicrex::XML::Element::parseOptionalStringParameterElement ( const char *  tagName,
const FPString defaultValue = FPString() 
) const

Parses a string value from a child element. Returns the provided default value if child element doesn't exist.

◆ parsePathParameterAttribute()

FPString atomicrex::XML::Element::parsePathParameterAttribute ( const char *  attributeName) const

Parses a file path from an XML element attribute. Throws an exception if attribute doesn't exist.

◆ parsePathParameterElement()

FPString atomicrex::XML::Element::parsePathParameterElement ( const char *  tagName) const

Parses a file path from a child element. Throws an exception if child element doesn't exist.

◆ parseStringParameterAttribute()

FPString atomicrex::XML::Element::parseStringParameterAttribute ( const char *  attributeName) const

Parses a single string parameter from an XML element attribute. Throws an exception if attribute doesn't exist.

◆ parseStringParameterElement()

FPString atomicrex::XML::Element::parseStringParameterElement ( const char *  tagName) const

Parses a string value from a child element. Throws an exception if child element doesn't exist.

◆ resolveFilename()

FPString atomicrex::XML::Element::resolveFilename ( const FPString filename) const
protected

Resolves a relative path or filename to an absolute path by using the base path of the XML document.

◆ setTextContent()

void atomicrex::XML::Element::setTextContent ( const FPString text)

Sets the text content of the element. When calling this, make sure the element does not have any child elements.


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