GEOS
Public Member Functions | Static Public Attributes | List of all members
geos::xmlWrapper::xmlDocument Class Reference

#include <xmlWrapper.hpp>

Public Member Functions

 xmlDocument ()
 Construct an empty xmlDocument that waits to load something.
 
 xmlDocument (const xmlDocument &)=delete
 non-copyable
 
 xmlDocument (xmlDocument &&)=default
 move constructor
 
xmlNode getFirstChild () const
 
xmlNode getChild (string const &name) const
 
string const & getOriginalBuffer () const
 
string const * getOriginalBuffer (string const &filePath) const
 
map< string, string > const & getOriginalBuffers () const
 
string const & getFilePath () const
 
xmlNodePos getNodePosition (xmlWrapper::xmlNode const &node) const
 If the node file information are loaded, compute the position of a node. More...
 
xmlResult loadString (string_view content, bool loadNodeFileInfo=false)
 Load document from zero-terminated string. No encoding conversions are applied. Free any previously loaded xml tree. Wrapper of pugi::xml_document::loadBuffer() method. More...
 
xmlResult loadFile (string const &path, bool loadNodeFileInfo=false)
 Load document from file. Free any previously loaded xml tree. Wrapper of pugi::xml_document::loadBuffer() method. More...
 
xmlNode appendChild (string const &name)
 Add a root element to the document. More...
 
xmlNode appendChild (xmlNodeType type=xmlNodeType::node_element)
 Add a root element to the document. More...
 
bool saveFile (string const &path) const
 Save the XML to a file. More...
 
void addIncludedXML (xmlNode &targetNode, int level=0)
 Function to add xml nodes from included files. More...
 
bool hasNodeFileInfo () const
 

Static Public Attributes

static constexpr size_t npos = string::npos
 Error value for when an offset / line position is undefined.
 

Detailed Description

Wrapper class for the type of xml document. This class exists to intercept file / string loading methods, and to keep the loaded buffers, in order to retrieve the source file and line of nodes and attributes.

Definition at line 146 of file xmlWrapper.hpp.

Member Function Documentation

◆ addIncludedXML()

void geos::xmlWrapper::xmlDocument::addIncludedXML ( xmlNode targetNode,
int  level = 0 
)

Function to add xml nodes from included files.

Parameters
targetNodethe node for which to look for included children specifications
levelinclude tree level used to detect circular includes

This function looks for a "Included" node under the targetNode, loops over all subnodes under the "Included" node, and then parses the file specified in those subnodes taking all the nodes in the file and adding them to the targetNode. Each found includes are added to xmlDocument::m_originalBuffers.

◆ appendChild() [1/2]

xmlNode geos::xmlWrapper::xmlDocument::appendChild ( string const &  name)

Add a root element to the document.

Parameters
namethe tag name of the node to add
Returns
the added node

◆ appendChild() [2/2]

xmlNode geos::xmlWrapper::xmlDocument::appendChild ( xmlNodeType  type = xmlNodeType::node_element)

Add a root element to the document.

Parameters
typethe type of the node to add to the root of the document. As an exemple, node_declaration is useful to add the "<?xml ?>" node.
Returns
the added node

◆ getChild()

xmlNode geos::xmlWrapper::xmlDocument::getChild ( string const &  name) const
Returns
a child with the specified name
Parameters
namethe tag name of the node to find

◆ getFilePath()

string const& geos::xmlWrapper::xmlDocument::getFilePath ( ) const
Returns
If loadFile() has been loaded, returns the path of the source file. If another load method has been called, it returns a generated unique value.

◆ getFirstChild()

xmlNode geos::xmlWrapper::xmlDocument::getFirstChild ( ) const
Returns
the first child of this document (typically in GEOS, the Problem node)

◆ getNodePosition()

xmlNodePos geos::xmlWrapper::xmlDocument::getNodePosition ( xmlWrapper::xmlNode const &  node) const

If the node file information are loaded, compute the position of a node.

Parameters
nodethe node to locate
Returns
an xmlNodePos object that represents the position of the target node.
Exceptions
anInputError if the node position is not found and source file is loaded.

◆ getOriginalBuffer() [1/2]

string const& geos::xmlWrapper::xmlDocument::getOriginalBuffer ( ) const
Returns
the original file buffer loaded during the last load_X() call on this object.

◆ getOriginalBuffer() [2/2]

string const* geos::xmlWrapper::xmlDocument::getOriginalBuffer ( string const &  filePath) const
Returns
If the specified file at the "filePath" is the loaded document of the instance, or one of its includes, returns its original buffer as a string. Returns nullptr if filePath is not a loaded and available document.
Parameters
filePaththe path of the file which buffer must be returned.

◆ getOriginalBuffers()

map< string, string > const& geos::xmlWrapper::xmlDocument::getOriginalBuffers ( ) const
Returns
a map containing the original buffers of the document and its includes, indexed by file path.

◆ hasNodeFileInfo()

bool geos::xmlWrapper::xmlDocument::hasNodeFileInfo ( ) const
Returns
True if loadNodeFileInfo was true during the last load_X call.

◆ loadFile()

xmlResult geos::xmlWrapper::xmlDocument::loadFile ( string const &  path,
bool  loadNodeFileInfo = false 
)

Load document from file. Free any previously loaded xml tree. Wrapper of pugi::xml_document::loadBuffer() method.

Parameters
paththe path of an xml file to load.
loadNodeFileInfoLoad the node source file info, allowing getNodePosition() to work.
Returns
an xmlResult object representing the parsing resulting status.

◆ loadString()

xmlResult geos::xmlWrapper::xmlDocument::loadString ( string_view  content,
bool  loadNodeFileInfo = false 
)

Load document from zero-terminated string. No encoding conversions are applied. Free any previously loaded xml tree. Wrapper of pugi::xml_document::loadBuffer() method.

Parameters
contentthe string containing the document content
loadNodeFileInfoLoad the node source file info, allowing getNodePosition() to work.
Returns
an xmlResult object representing the parsing resulting status.

◆ saveFile()

bool geos::xmlWrapper::xmlDocument::saveFile ( string const &  path) const

Save the XML to a file.

Parameters
paththe file path
Returns
true if the file has successfuly been saved
false otherwise

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