Cantera 2.6.0

Public Member Functions | Protected Attributes | Private Member Functions | List of all members
XML_Node Class Reference

Class XML_Node is a tree-based representation of the contents of an XML file. More...

`#include <xml.h>`

Collaboration diagram for XML_Node:
[legend]

## Public Member Functions
| XML_Node (const std::string &nm="--", XML_Node *const parent=0)
| Constructor for XML_Node, representing a tree structure. More...
| XML_Node (const XML_Node &right)
XML_Node & | operator= (const XML_Node &right)
void | clear ()
| Clear the current node and everything under it. More...
XML_Node & | mergeAsChild (XML_Node &node)
| Merge an existing node as a child node to the current node. More...
XML_Node & | addChild (const XML_Node &node)
XML_Node & | addChild (const std::string &sname)
| Add a child node to the current node with a specified name. More...
XML_Node & | addChild (const std::string &name, const std::string &value)
| Add a child node to the current XML node, and at the same time add a value to the child. More...
XML_Node & | addChild (const std::string &name, const doublereal value, const std::string &fmt="%g")
| Add a child node to the current XML node, and at the same time add a formatted value to the child. More...
void | removeChild (const XML_Node *const node)
| Remove a child from this node's list of children. More...
void | addComment (const std::string &comment)
| Add a child node to the current node containing a comment. More...
void | addValue (const std::string &val)
| Modify the value for the current node. More...
void | addValue (const doublereal val, const std::string &fmt="%g")
| Modify the value for the current node. More...
std::string | value () const
| Return the value of an XML node as a string. More...
std::string | value (const std::string &cname) const
| Return the value of an XML child node as a string. More...
std::string | operator() (const std::string &cname) const
| The Overloaded parenthesis operator with one augment returns the value of an XML child node as a string. More...
doublereal | fp_value () const
| Return the value of an XML node as a single double. More...
integer | int_value () const
| Return the value of an XML node as a single int. More...
void | addAttribute (const std::string &attrib, const std::string &value)
| Add or modify an attribute of the current node. More...
void | addAttribute (const std::string &attrib, const doublereal value, const std::string &fmt="%g")
| Add or modify an attribute to the double, value. More...
void | addAttribute (const std::string &attrib, int value)
| Add an integer attribute. More...
void | addAttribute (const std::string &attrib, size_t value)
| Add an unsigned integer attribute. More...
std::string | operator[] (const std::string &attr) const
| The operator[] is overloaded to provide a lookup capability on attributes for the current XML element. More...
std::string | attrib (const std::string &attr) const
| Function returns the value of an attribute. More...
const std::map< std::string, std::string > & | attribsConst () const
| Returns an unchangeable value of the attributes map for the current node. More...
void | setLineNumber (const int n)
| Set the line number. More...
int | lineNumber () const
| Return the line number. More...
XML_Node * | parent () const
| Returns a pointer to the parent node of the current node. More...
XML_Node * | setParent (XML_Node *const p)
| Sets the pointer for the parent node of the current node. More...
bool | hasChild (const std::string &ch) const
| Tests whether the current node has a child node with a particular name. More...
bool | hasAttrib (const std::string &a) const
| Tests whether the current node has an attribute with a particular name. More...
std::string | name () const
| Returns the name of the XML node. More...
void | setName (const std::string &name_)
| Sets the name of the XML node. More...
std::string | id () const
| Return the id attribute, if present. More...
XML_Node & | child (const size_t n) const
| Return a changeable reference to the n'th child of the current node. More...
const std::vector< XML_Node * > & | children () const
| Return an unchangeable reference to the vector of children of the current node. More...
size_t | nChildren (bool discardComments=false) const
| Return the number of children. More...
bool | isComment () const
| Boolean function indicating whether a comment. More...
void | _require (const std::string &a, const std::string &v) const
| Require that the current XML node has an attribute named by the first argument, a, and that this attribute has the string value listed in the second argument, v. More...
XML_Node * | findNameID (const std::string &nameTarget, const std::string &idTarget) const
| This routine carries out a recursive search for an XML node based on both the XML element name and the attribute ID. More...
XML_Node * | findNameIDIndex (const std::string &nameTarget, const std::string &idTarget, const int index) const
| This routine carries out a search for an XML node based on the XML element name, the attribute ID and an integer index. More...
XML_Node * | findID (const std::string &id, const int depth=100) const
| This routine carries out a recursive search for an XML node based on the XML element attribute "id". More...
XML_Node * | findByAttr (const std::string &attr, const std::string &val, int depth=100000) const
| This routine carries out a recursive search for an XML node based on an attribute of each XML node. More...
const XML_Node * | findByName (const std::string &nm, int depth=100000) const
| This routine carries out a recursive search for an XML node based on the name of the node. More...
XML_Node * | findByName (const std::string &nm, int depth=100000)
| This routine carries out a recursive search for an XML node based on the name of the node. More...
std::vector< XML_Node * > | getChildren (const std::string &name) const
| Get a vector of pointers to XML_Node containing all of the children of the current node which match the given name. More...
XML_Node & | child (const std::string &loc) const
| Return a changeable reference to a child of the current node, named by the argument. More...
void | writeHeader (std::ostream &s)
| Write the header to the XML file to the specified ostream. More...
void | write (std::ostream &s, const int level=0, int numRecursivesAllowed=60000) const
| Write an XML subtree to an output stream. More...
XML_Node & | root () const
| Return the root of the current XML_Node tree. More...
void | setRoot (const XML_Node &root)
| Set the root XML_Node value within the current node. More...
void | build (const std::string &filename)
| Populate the XML tree from an input file. More...
void | build (std::istream &f, const std::string &filename="[unknown]")
| Main routine to create an tree-like representation of an XML file. More...
void | copyUnion (XML_Node *const node_dest) const
| Copy all of the information in the current XML_Node tree into the destination XML_Node tree, doing a union operation as we go. More...
void | copy (XML_Node *const node_dest) const
| Copy all of the information in the current XML_Node tree into the destination XML_Node tree, doing a complete copy as we go. More...
void | lock ()
| Set the lock for this node and all of its children. More...
void | unlock ()
| Unset the lock for this node and all of its children. More...

## Protected Attributes
std::string | m_name
| XML node name of the node. More...
std::string | m_value
| Value of the XML node. More...
std::string | m_filename
| Name of the file from which this XML node was read. More...
std::multimap< std::string, XML_Node * > | m_childindex
| Map containing an index between the node name and the pointer to the node. More...
std::map< std::string, std::string > | m_attribs
| Storage of attributes for a node. More...
XML_Node * | m_parent
| Pointer to the parent XML_Node for the current node. More...
XML_Node * | m_root
| Pointer to the root XML_Node for the current node. More...
bool | m_locked
| Lock for this node. More...
std::vector< XML_Node * > | m_children
| Vector of pointers to child nodes. More...
bool | m_iscomment
| True if the current node is a comment node. More...
int | m_linenum
| The member data m_linenum. More...

## Private Member Functions
std::map< std::string, std::string > & | attribs ()
| Returns a changeable value of the attributes map for the current node. More...
void | write_int (std::ostream &s, int level=0, int numRecursivesAllowed=60000) const
| Write an XML subtree to an output stream. More...

## Detailed Description

Class XML_Node is a tree-based representation of the contents of an XML file.

There are routines for adding to the tree, querying and searching the tree, and for writing the tree out to an output file.

Deprecated:
  The XML input format is deprecated and will be removed in Cantera 3.0.

Definition at line 102 of file xml.h.

## Constructor & Destructor Documentation

## ◆ XML_Node() [1/2]

XML_Node | ( | const std::string & | nm = `"--"`,
|  | XML_Node *const | parent = `0`
| ) |  |
| explicit

Constructor for XML_Node, representing a tree structure.

Parameters

  nm | Name of the node.
  parent | Pointer to the parent for this node in the tree. A value of 0 indicates this is the top of the tree.

Definition at line 310 of file xml.cpp.

References XML_Node::m_root, and XML_Node::root().

Referenced by XML_Node::addChild().

## ◆ XML_Node() [2/2]

XML_Node | ( | const XML_Node & | right | ) |

Definition at line 325 of file xml.cpp.

## ◆ ~XML_Node()

~XML_Node | ( |  | ) |
| virtual

Definition at line 353 of file xml.cpp.

## Member Function Documentation

## ◆ operator=()

XML_Node & operator= | ( | const XML_Node & | right | ) |

Definition at line 338 of file xml.cpp.

## ◆ clear()

void clear | ( |  | ) |

Clear the current node and everything under it.

The value, attributes and children are all zeroed. The name and the parent information is kept.

Definition at line 366 of file xml.cpp.

References XML_Node::m_attribs, XML_Node::m_childindex, XML_Node::m_children, XML_Node::m_iscomment, XML_Node::m_linenum, XML_Node::m_value, and XML_Node::parent().

Referenced by Cantera::getFloatArray().

## ◆ mergeAsChild()

XML_Node & mergeAsChild | ( | XML_Node & | node | ) |

Merge an existing node as a child node to the current node.

This will merge an XML_Node as a child to the current node. Note, this actually adds the node. Therefore, the current node is changed. There is no copy made of the child node. The child node should not be deleted in the future

Parameters

  node | Reference to a child XML_Node object

Returns
  a reference to the added child node

Definition at line 383 of file xml.cpp.

References XML_Node::m_childindex, XML_Node::m_children, XML_Node::name(), XML_Node::root(), XML_Node::setParent(), and XML_Node::setRoot().

Referenced by XML_Node::addChild().

## ◆ addChild() [1/4]

XML_Node & addChild | ( | const XML_Node & | node | ) |

Definition at line 392 of file xml.cpp.

## ◆ addChild() [2/4]

XML_Node & addChild | ( | const std::string & | sname | ) |

Add a child node to the current node with a specified name.

This will add an XML_Node as a child to the current node. The node will be blank except for the specified name.

Parameters

  sname | Name of the new child

Returns
  a reference to the added node

Definition at line 397 of file xml.cpp.

References XML_Node::mergeAsChild(), and XML_Node::XML_Node().

## ◆ addChild() [3/4]

XML_Node & addChild | ( | const std::string & | name,
|  | const std::string & | value
| ) |  |

Add a child node to the current XML node, and at the same time add a value to the child.

Resulting XML string:

     <name> value </name>

Parameters

  name | Name of the child XML_Node object
  value | Value of the XML_Node - string

Returns
  a reference to the created child XML_Node object

Definition at line 402 of file xml.cpp.

References XML_Node::addValue(), XML_Node::name(), and XML_Node::value().

## ◆ addChild() [4/4]

XML_Node & addChild | ( | const std::string & | name,
|  | const doublereal | value,
|  | const std::string & | fmt = `"%g"`
| ) |  |

Add a child node to the current XML node, and at the same time add a formatted value to the child.

This version supplies a formatting string (printf format) to the output of the value.

Resulting XML string:

     <name> value </name>

Parameters

  name | Name of the child XML_Node object
  value | Value of the XML_Node - double.
  fmt | Format of the output for value

Returns
  a reference to the created child XML_Node object

Definition at line 409 of file xml.cpp.

References XML_Node::addValue(), XML_Node::name(), and XML_Node::value().

## ◆ removeChild()

void removeChild | ( | const XML_Node *const | node | ) |

Remove a child from this node's list of children.

This function removes an XML_Node from the children of this node.

Parameters

  node | Pointer to the node to be removed. Note, this node isn't modified in any way.

Definition at line 417 of file xml.cpp.

References XML_Node::m_childindex, XML_Node::m_children, and XML_Node::name().

## ◆ addComment()

void addComment | ( | const std::string & | comment | ) |

Add a child node to the current node containing a comment.

Child node will have the name, comment.

Parameters

  comment | Content of the comment

Definition at line 424 of file xml.cpp.

Referenced by XML_Node::build().

## ◆ addValue() [1/2]

void addValue | ( | const std::string & | val | ) |

Modify the value for the current node.

This functions fills in the m_value field of the current node

Parameters

  val | string Value that the node will be assigned

Definition at line 429 of file xml.cpp.

References XML_Node::m_iscomment, XML_Node::m_name, and XML_Node::m_value.

Referenced by XML_Node::addChild(), XML_Node::build(), XML_Node::copy(), and XML_Node::copyUnion().

## ◆ addValue() [2/2]

void addValue | ( | const doublereal | val,
|  | const std::string & | fmt = `"%g"`
| ) |  |

Modify the value for the current node.

This functions fills in the m_value field of the current node with a formatted double value

Parameters

  val | double Value that the node will be assigned
  fmt | Format of the printf string conversion of the double. Default is "%g". Must be less than 63 chars

Definition at line 437 of file xml.cpp.

References XML_Node::m_value, and Cantera::trimCopy().

## ◆ value() [1/2]

std::string value | ( |  | ) | const

Return the value of an XML node as a string.

This is a simple accessor routine

Definition at line 442 of file xml.cpp.

References XML_Node::m_value.

Referenced by XML_Node::addAttribute(), XML_Node::addChild(), Cantera::checkElectrochemReaction(), Cantera::getFloatArray(), Cantera::getInteger(), Cantera::getString(), Cantera::getStringArray(), MaskellSolidSolnPhase::initThermoXML(), Cantera::newSpecies(), XML_Node::operator()(), StFlow::restore(), LatticeSolidPhase::setParametersFromXML(), PDSS_IonsFromNeutral::setParametersFromXML(), and XML_Node::value().

## ◆ value() [2/2]

std::string value | ( | const std::string & | cname | ) | const

Return the value of an XML child node as a string.

Parameters

  cname | Name of the child node to the current node, for which you want the value

Definition at line 447 of file xml.cpp.

References XML_Node::child(), and XML_Node::value().

## ◆ operator()()

std::string operator() | ( | const std::string & | cname | ) | const

The Overloaded parenthesis operator with one augment returns the value of an XML child node as a string.

Parameters

  cname | Name of the child node to the current node, for which you want the value

Definition at line 452 of file xml.cpp.

References XML_Node::value().

## ◆ fp_value()

doublereal fp_value | ( |  | ) | const

Return the value of an XML node as a single double.

This accesses the value string, and then tries to interpret it as a single double value.

Definition at line 457 of file xml.cpp.

References Cantera::fpValueCheck(), and XML_Node::m_value.

Referenced by Inlet1D::restore(), OutletRes1D::restore(), and ReactingSurf1D::restore().

## ◆ int_value()

integer int_value | ( |  | ) | const

Return the value of an XML node as a single int.

This accesses the value string, and then tries to interpret it as a single int value.

Definition at line 462 of file xml.cpp.

References XML_Node::m_value.

Referenced by Cantera::getInteger(), and Cantera::getIntegers().

## ◆ addAttribute() [1/4]

void addAttribute | ( | const std::string & | attrib,
|  | const std::string & | value
| ) |  |

Add or modify an attribute of the current node.

This functions fills in the m_value field of the current node with a string value

Parameters

  attrib | String name for the attribute to be assigned
  value | String value that the attribute will have

Definition at line 467 of file xml.cpp.

References XML_Node::attrib(), XML_Node::m_attribs, and XML_Node::value().

Referenced by Cantera::addString(), XML_Node::copy(), XML_Node::copyUnion(), Inlet1D::save(), Empty1D::save(), Symm1D::save(), Outlet1D::save(), OutletRes1D::save(), Surf1D::save(), ReactingSurf1D::save(), Domain1D::save(), and StFlow::save().

## ◆ addAttribute() [2/4]

void addAttribute | ( | const std::string & | attrib,
|  | const doublereal | value,
|  | const std::string & | fmt = `"%g"`
| ) |  |

Add or modify an attribute to the double, value.

This functions fills in the attribute field, named attrib, with the double value, value. A formatting string is used.

Parameters

  attrib | String name for the attribute to be assigned
  value | double Value that the node will be assigned
  fmt | Format of the printf string conversion of the double. Default is "%g".

Definition at line 472 of file xml.cpp.

References XML_Node::attrib(), and XML_Node::m_attribs.

## ◆ addAttribute() [3/4]

void addAttribute | ( | const std::string & | attrib,
|  | int | value
| ) |  |

Add an integer attribute.

Parameters

  attrib | String name for the attribute to be assigned
  value | int Value that the node will be assigned

Definition at line 478 of file xml.cpp.

References XML_Node::m_attribs.

## ◆ addAttribute() [4/4]

void addAttribute | ( | const std::string & | attrib,
|  | size_t | value
| ) |  |

Add an unsigned integer attribute.

Parameters

  attrib | String name for the attribute to be assigned
  value | int Value that the node will be assigned

Definition at line 483 of file xml.cpp.

References XML_Node::m_attribs.

## ◆ operator[]()

std::string operator[] | ( | const std::string & | attr | ) | const

The operator[] is overloaded to provide a lookup capability on attributes for the current XML element.

For example xmlNode["id"] will return the value of the attribute "id" for the current XML element. It will return the blank std::string if there isn't an attribute with that name.

Parameters

  attr | attribute string to look up

Returns
  a string representing the value of the attribute within the XML node. If there is no attribute with the given name, it returns the null string.

Definition at line 488 of file xml.cpp.

References XML_Node::attrib().

## ◆ attrib()

std::string attrib | ( | const std::string & | attr | ) | const

Function returns the value of an attribute.

This function searches the attributes vector for the attribute named 'attr'. If a match is found, the attribute value is returned as a string. If no match is found, the empty string is returned.

Parameters

  attr | String containing the attribute to be searched for.

Returns
  If a match is found, the attribute value is returned as a string. If no match is found, the empty string is returned.

Definition at line 493 of file xml.cpp.

References XML_Node::m_attribs.

Referenced by XML_Node::_require(), XML_Node::addAttribute(), XML_Node::copyUnion(), XML_Node::findByAttr(), XML_Node::findID(), XML_Node::findNameIDIndex(), Cantera::getFloatArray(), Cantera::getString(), XML_Node::id(), Cantera::importPhase(), DebyeHuckel::initThermoXML(), HMWSoln::initThermoXML(), IdealSolnGasVPSS::initThermoXML(), IdealMolalSoln::initThermoXML(), BinarySolutionTabulatedThermo::initThermoXML(), Cantera::installElements(), Cantera::installReactionArrays(), Cantera::newMu0ThermoFromXML(), Cantera::newSpecies(), TransportFactory::newTransport(), XML_Node::operator[](), HMWSoln::readXMLBinarySalt(), MargulesVPSSTP::readXMLBinarySpecies(), RedlichKisterVPSSTP::readXMLBinarySpecies(), RedlichKwongMFTP::readXMLCrossFluid(), HMWSoln::readXMLLambdaNeutral(), HMWSoln::readXMLMunnnNeutral(), HMWSoln::readXMLPsi(), RedlichKwongMFTP::readXMLPureFluid(), HMWSoln::readXMLTheta(), HMWSoln::readXMLZetaCation(), Inlet1D::restore(), OutletRes1D::restore(), ReactingSurf1D::restore(), PDSS_ConstVol::setParametersFromXML(), PDSS_HKFT::setParametersFromXML(), PDSS_IonsFromNeutral::setParametersFromXML(), and PDSS_SSVol::setParametersFromXML().

## ◆ attribs()

std::map< std::string, std::string > & attribs | ( |  | ) |
| private

Returns a changeable value of the attributes map for the current node.

Note this is a simple accessor routine. And, it is a private function. It's used in some internal copy and assignment routines

Definition at line 498 of file xml.cpp.

References XML_Node::m_attribs.

Referenced by XML_Node::build().

## ◆ attribsConst()

const std::map< std::string, std::string > & attribsConst | ( |  | ) | const

Returns an unchangeable value of the attributes map for the current node.

Definition at line 503 of file xml.cpp.

References XML_Node::m_attribs.

## ◆ setLineNumber()

void setLineNumber | ( | const int | n | ) |

Set the line number.

Parameters

  n | the member data m_linenum is set to n

Definition at line 508 of file xml.cpp.

References XML_Node::m_linenum.

Referenced by XML_Node::build(), and XML_Node::copy().

## ◆ lineNumber()

int lineNumber | ( |  | ) | const

Return the line number.

Definition at line 513 of file xml.cpp.

References XML_Node::m_linenum.

Referenced by XML_Node::child().

## ◆ parent()

XML_Node * parent | ( |  | ) | const

Returns a pointer to the parent node of the current node.

Definition at line 518 of file xml.cpp.

References XML_Node::m_parent.

Referenced by XML_Node::build(), XML_Node::clear(), Cantera::getByTitle(), and Cantera::importKinetics().

## ◆ setParent()

XML_Node * setParent | ( | XML_Node *const | p | ) |

Sets the pointer for the parent node of the current node.

Parameters

  p | Pointer to the parent node

Returns
  the pointer p

Definition at line 523 of file xml.cpp.

References XML_Node::m_parent.

Referenced by XML_Node::mergeAsChild().

## ◆ hasChild()

bool hasChild | ( | const std::string & | ch | ) | const

Tests whether the current node has a child node with a particular name.

Parameters

  ch | Name of the child node to test

Returns
  true if the child node exists, false otherwise.

Definition at line 529 of file xml.cpp.

References XML_Node::m_childindex.

Referenced by Cantera::checkElectrochemReaction(), Cantera::getChildValue(), Cantera::getInteger(), Cantera::getOptionalModel(), Cantera::importKinetics(), Cantera::importPhase(), DebyeHuckel::initThermoXML(), HMWSoln::initThermoXML(), IdealSolidSolnPhase::initThermoXML(), IdealSolnGasVPSS::initThermoXML(), MargulesVPSSTP::initThermoXML(), MaskellSolidSolnPhase::initThermoXML(), RedlichKisterVPSSTP::initThermoXML(), RedlichKwongMFTP::initThermoXML(), StoichSubstance::initThermoXML(), ThermoPhase::initThermoXML(), IdealMolalSoln::initThermoXML(), BinarySolutionTabulatedThermo::initThermoXML(), Cantera::installElements(), Cantera::installReactionArrays(), Cantera::newMu0ThermoFromXML(), Cantera::newNasa9ThermoFromXML(), Cantera::newSpecies(), TransportFactory::newTransport(), StFlow::restore(), PDSS_HKFT::setParametersFromXML(), IonsFromNeutralVPSSTP::setParametersFromXML(), MixtureFugacityTP::setStateFromXML(), MolalityVPSSTP::setStateFromXML(), SurfPhase::setStateFromXML(), and ThermoPhase::setStateFromXML().

## ◆ hasAttrib()

bool hasAttrib | ( | const std::string & | a | ) | const

Tests whether the current node has an attribute with a particular name.

Parameters

  a | Name of the attribute to test

Returns
  true if the attribute exists, false otherwise.

Definition at line 534 of file xml.cpp.

References XML_Node::m_attribs.

Referenced by XML_Node::_require(), XML_Node::copyUnion(), XML_Node::findByAttr(), XML_Node::findID(), XML_Node::id(), Cantera::importPhase(), DebyeHuckel::initThermoXML(), Cantera::installElements(), Cantera::newNasa9ThermoFromXML(), and Cantera::newNasaThermoFromXML().

## ◆ name()

std::string name | ( |  | ) | const
| inline

Returns the name of the XML node.

Definition at line 371 of file xml.h.

References XML_Node::m_name.

Referenced by XML_Node::_require(), XML_Node::addChild(), XML_Node::build(), XML_Node::copy(), XML_Node::copyUnion(), XML_Node::findByName(), XML_Node::findNameID(), XML_Node::findNameIDIndex(), Cantera::findXMLPhase(), XML_Node::getChildren(), Cantera::getFloatArray(), Cantera::getInteger(), Cantera::getString(), Cantera::importPhase(), MargulesVPSSTP::initThermoXML(), RedlichKisterVPSSTP::initThermoXML(), RedlichKwongMFTP::initThermoXML(), XML_Node::mergeAsChild(), Cantera::newNasa9ThermoFromXML(), HMWSoln::readXMLBinarySalt(), MargulesVPSSTP::readXMLBinarySpecies(), RedlichKisterVPSSTP::readXMLBinarySpecies(), RedlichKwongMFTP::readXMLCrossFluid(), HMWSoln::readXMLLambdaNeutral(), HMWSoln::readXMLMunnnNeutral(), HMWSoln::readXMLPsi(), RedlichKwongMFTP::readXMLPureFluid(), HMWSoln::readXMLTheta(), HMWSoln::readXMLZetaCation(), XML_Node::removeChild(), Inlet1D::restore(), OutletRes1D::restore(), ReactingSurf1D::restore(), PDSS_ConstVol::setParametersFromXML(), PDSS_HKFT::setParametersFromXML(), PDSS_IonsFromNeutral::setParametersFromXML(), PDSS_SSVol::setParametersFromXML(), and Cantera::speciesXML_Node().

## ◆ setName()

void setName | ( | const std::string & | name_ | ) |
| inline

Sets the name of the XML node.

Parameters

  name_ | The name of the XML node

Definition at line 379 of file xml.h.

References XML_Node::m_name.

Referenced by XML_Node::build(), and XML_Node::copy().

## ◆ id()

std::string id | ( |  | ) | const

Return the id attribute, if present.

Returns the id attribute if present. If not it return the empty string

Definition at line 539 of file xml.cpp.

References XML_Node::attrib(), and XML_Node::hasAttrib().

Referenced by XML_Node::findNameID(), XML_Node::findNameIDIndex(), Cantera::findXMLPhase(), Cantera::importPhase(), DebyeHuckel::initThermoXML(), HMWSoln::initThermoXML(), IdealSolidSolnPhase::initThermoXML(), MargulesVPSSTP::initThermoXML(), MaskellSolidSolnPhase::initThermoXML(), RedlichKisterVPSSTP::initThermoXML(), IdealMolalSoln::initThermoXML(), BinarySolutionTabulatedThermo::initThermoXML(), and Phase::setXMLdata().

## ◆ child() [1/2]

XML_Node & child | ( | const size_t | n | ) | const

Return a changeable reference to the n'th child of the current node.

Parameters

  n | Number of the child to return

Definition at line 547 of file xml.cpp.

References XML_Node::m_children.

Referenced by Cantera::checkElectrochemReaction(), Cantera::formSpeciesXMLNodeList(), XML_Node::getChildren(), Cantera::getInteger(), Cantera::getOptionalModel(), Cantera::getReactions(), Cantera::getSpecies(), Cantera::importKinetics(), Cantera::importPhase(), DebyeHuckel::initThermoXML(), HMWSoln::initThermoXML(), IdealSolidSolnPhase::initThermoXML(), IdealSolnGasVPSS::initThermoXML(), MargulesVPSSTP::initThermoXML(), MaskellSolidSolnPhase::initThermoXML(), RedlichKisterVPSSTP::initThermoXML(), RedlichKwongMFTP::initThermoXML(), StoichSubstance::initThermoXML(), ThermoPhase::initThermoXML(), IdealMolalSoln::initThermoXML(), BinarySolutionTabulatedThermo::initThermoXML(), Cantera::installElements(), Cantera::installReactionArrays(), KineticsFactory::newKinetics(), Cantera::newNasa9ThermoFromXML(), Cantera::newNasaThermoFromXML(), Cantera::newPhase(), Cantera::newSpecies(), TransportFactory::newTransport(), RedlichKisterVPSSTP::readXMLBinarySpecies(), RedlichKwongMFTP::readXMLCrossFluid(), RedlichKwongMFTP::readXMLPureFluid(), Inlet1D::restore(), OutletRes1D::restore(), ReactingSurf1D::restore(), StFlow::restore(), LatticeSolidPhase::setParametersFromXML(), IonsFromNeutralVPSSTP::setParametersFromXML(), and XML_Node::value().

## ◆ children()

const std::vector< XML_Node * > & children | ( |  | ) | const

Return an unchangeable reference to the vector of children of the current node.

Each of the individual XML_Node child pointers, however, is pointing to a changeable XML node object.

Definition at line 552 of file xml.cpp.

References XML_Node::m_children.

Referenced by XML_Node::copy(), XML_Node::copyUnion(), Cantera::findXMLPhase(), HMWSoln::initThermoXML(), Cantera::newSpeciesThermoInterpType(), and XML_NoChild::XML_NoChild().

## ◆ nChildren()

size_t nChildren | ( | bool | discardComments = `false` | ) | const

Return the number of children.

Parameters

  discardComments | If true comments are discarded when adding up the number of children. Defaults to false.

Definition at line 557 of file xml.cpp.

References XML_Node::isComment(), and XML_Node::m_children.

Referenced by XML_Node::copy(), XML_Node::copyUnion(), XML_Node::findByAttr(), XML_Node::findByName(), XML_Node::findID(), Cantera::findXMLPhase(), Cantera::formSpeciesXMLNodeList(), XML_Node::getChildren(), MargulesVPSSTP::initThermoXML(), RedlichKisterVPSSTP::initThermoXML(), RedlichKwongMFTP::initThermoXML(), RedlichKisterVPSSTP::readXMLBinarySpecies(), RedlichKwongMFTP::readXMLCrossFluid(), RedlichKwongMFTP::readXMLPureFluid(), Inlet1D::restore(), OutletRes1D::restore(), and ReactingSurf1D::restore().

## ◆ isComment()

bool isComment | ( |  | ) | const

Boolean function indicating whether a comment.

Definition at line 572 of file xml.cpp.

References XML_Node::m_iscomment.

Referenced by XML_Node::nChildren().

## ◆ _require()

void _require | ( | const std::string & | a,
|  | const std::string & | v
| ) |  | const

Require that the current XML node has an attribute named by the first argument, a, and that this attribute has the string value listed in the second argument, v.

Parameters

  a | attribute name
  v | required value of the attribute

If the condition is not true, an exception is thrown

Definition at line 577 of file xml.cpp.

References XML_Node::attrib(), XML_Node::hasAttrib(), and XML_Node::name().

Referenced by LatticePhase::setParametersFromXML(), LatticeSolidPhase::setParametersFromXML(), MetalPhase::setParametersFromXML(), PureFluidPhase::setParametersFromXML(), WaterSSTP::setParametersFromXML(), EdgePhase::setParametersFromXML(), and SurfPhase::setParametersFromXML().

## ◆ findNameID()

XML_Node * findNameID | ( | const std::string & | nameTarget,
|  | const std::string & | idTarget
| ) |  | const

This routine carries out a recursive search for an XML node based on both the XML element name and the attribute ID.

If exact matches are found for both fields, the pointer to the matching XML Node is returned.

The ID attribute may be defaulted by setting it to "". In this case the pointer to the first XML element matching the name only is returned.

Parameters

  nameTarget | Name of the XML Node that is being searched for
  idTarget | "id" attribute of the XML Node that the routine looks for

Returns
  the pointer to the XML node that fits the criteria

This algorithm does a lateral search of first generation children first before diving deeper into each tree branch.

Definition at line 587 of file xml.cpp.

References XML_Node::findNameID(), XML_Node::id(), XML_Node::m_children, and XML_Node::name().

Referenced by XML_Node::findNameID(), and Cantera::get_XML_NameID().

## ◆ findNameIDIndex()

XML_Node * findNameIDIndex | ( | const std::string & | nameTarget,
|  | const std::string & | idTarget,
|  | const int | index
| ) |  | const

This routine carries out a search for an XML node based on the XML element name, the attribute ID and an integer index.

If exact matches are found for all fields, the pointer to the matching XML Node is returned. The search is only carried out on the current element and the child elements of the current element.

The "id" attribute may be defaulted by setting it to "". In this case the pointer to the first XML element matching the name and the Index is returned.

Parameters

  nameTarget | Name of the XML Node that is being searched for
  idTarget | "id" attribute of the XML Node that the routine looks for
  index | Integer describing the index. The index is an attribute of the form index = "3"

Returns
  the pointer to the XML node that fits the criteria

Definition at line 617 of file xml.cpp.

References XML_Node::attrib(), XML_Node::id(), XML_Node::m_children, and XML_Node::name().

## ◆ findID()

XML_Node * findID | ( | const std::string & | id,
|  | const int | depth = `100`
| ) |  | const

This routine carries out a recursive search for an XML node based on the XML element attribute "id".

If exact match is found, the pointer to the matching XML Node is returned. If not, 0 is returned.

Parameters

  id | "id" attribute of the XML Node that the routine looks for
  depth | Depth of the search.

Returns
  the pointer to the XML node that fits the criteria

This algorithm does a lateral search of first generation children first before diving deeper into each tree branch.

Definition at line 646 of file xml.cpp.

References XML_Node::attrib(), XML_Node::hasAttrib(), XML_Node::m_children, and XML_Node::nChildren().

Referenced by Cantera::get_XML_Node(), and Sim1D::restore().

## ◆ findByAttr()

XML_Node * findByAttr | ( | const std::string & | attr,
|  | const std::string & | val,
|  | int | depth = `100000`
| ) |  | const

This routine carries out a recursive search for an XML node based on an attribute of each XML node.

If exact match is found with respect to the attribute name and value of the attribute, the pointer to the matching XML Node is returned. If not, 0 is returned.

Parameters

  attr | Attribute of the XML Node that the routine looks for
  val | Value of the attribute
  depth | Depth of the search. A value of 1 means that only the immediate children are searched.

Returns
  the pointer to the XML node that fits the criteria

Definition at line 662 of file xml.cpp.

References XML_Node::attrib(), XML_Node::hasAttrib(), XML_Node::m_children, and XML_Node::nChildren().

Referenced by Cantera::getByTitle(), and Cantera::installElements().

## ◆ findByName() [1/2]

const XML_Node * findByName | ( | const std::string & | nm,
|  | int | depth = `100000`
| ) |  | const

This routine carries out a recursive search for an XML node based on the name of the node.

If exact match is found with respect to XML_Node name, the pointer to the matching XML Node is returned. If not, 0 is returned. This is the const version of the routine.

Parameters

  nm | Name of the XML node
  depth | Depth of the search. A value of 1 means that only the immediate children are searched.

Returns
  the pointer to the XML node that fits the criteria

Definition at line 680 of file xml.cpp.

References XML_Node::m_children, XML_Node::name(), and XML_Node::nChildren().

Referenced by Cantera::importPhase(), DebyeHuckel::initThermoXML(), Cantera::newSpecies(), PDSS_ConstVol::setParametersFromXML(), PDSS_HKFT::setParametersFromXML(), PDSS_IonsFromNeutral::setParametersFromXML(), and PDSS_SSVol::setParametersFromXML().

## ◆ findByName() [2/2]

XML_Node * findByName | ( | const std::string & | nm,
|  | int | depth = `100000`
| ) |  |

This routine carries out a recursive search for an XML node based on the name of the node.

If exact match is found with respect to XML_Node name, the pointer to the matching XML Node is returned. If not, 0 is returned. This is the non-const version of the routine.

Parameters

  nm | Name of the XML node
  depth | Depth of the search. A value of 1 means that only the immediate children are searched.

Returns
  the pointer to the XML node that fits the criteria

Definition at line 696 of file xml.cpp.

References XML_Node::m_children, XML_Node::name(), and XML_Node::nChildren().

## ◆ getChildren()

std::vector< XML_Node * > getChildren | ( | const std::string & | name | ) | const

Get a vector of pointers to XML_Node containing all of the children of the current node which match the given name.

Parameters

  name | Name of the XML_Node children to search for

Returns
  vector of pointers to child XML_Nodes with the matching name

Definition at line 712 of file xml.cpp.

References Cantera::caseInsensitiveEquals(), XML_Node::child(), XML_Node::name(), and XML_Node::nChildren().

Referenced by Cantera::formSpeciesXMLNodeList(), Cantera::getFloatArray(), Cantera::getIntegers(), Cantera::getReactions(), Cantera::getSpecies(), Cantera::importPhase(), Cantera::installReactionArrays(), Sim1D::restore(), Domain1D::restore(), StFlow::restore(), LatticeSolidPhase::setParametersFromXML(), and Cantera::speciesXML_Node().

## ◆ child() [2/2]

XML_Node & child | ( | const std::string & | loc | ) | const

Return a changeable reference to a child of the current node, named by the argument.

Note the underlying data allows for more than one XML element with the same name. This routine returns the first child with the given name.

Parameters

  loc | Name of the child to return

Definition at line 723 of file xml.cpp.

References XML_Node::lineNumber(), XML_Node::m_childindex, XML_Node::m_filename, XML_Node::m_name, Cantera::npos, and XML_Node::root().

## ◆ writeHeader()

void writeHeader | ( | std::ostream & | s | ) |

Write the header to the XML file to the specified ostream.

Parameters

  s | ostream to write the output to

Definition at line 916 of file xml.cpp.

## ◆ write()

void write | ( | std::ostream & | s,
|  | const int | level = `0`,
|  | int | numRecursivesAllowed = `60000`
| ) |  | const

Write an XML subtree to an output stream.

This is a wrapper around the static routine write_int(). All this does is add an endl on to the output stream. write_int() is fine, but the last endl wasn't being written.

Parameters

  s | ostream to write to
  level | Indentation level to work from
  numRecursivesAllowed | Number of recursive calls allowed

Definition at line 1038 of file xml.cpp.

References Cantera::warn_deprecated(), and XML_Node::write_int().

## ◆ root()

XML_Node & root | ( |  | ) | const

Return the root of the current XML_Node tree.

Returns a reference to the root of the current XML tree

Definition at line 750 of file xml.cpp.

References XML_Node::m_root.

Referenced by XML_Node::build(), XML_Node::child(), Cantera::importPhase(), Cantera::installElements(), Cantera::installReactionArrays(), XML_Node::mergeAsChild(), Phase::setXMLdata(), and XML_Node::XML_Node().

## ◆ setRoot()

void setRoot | ( | const XML_Node & | root | ) |

Set the root XML_Node value within the current node.

Parameters

  root | Value of the root XML_Node.

Definition at line 755 of file xml.cpp.

References XML_Node::m_children, and XML_Node::m_root.

Referenced by XML_Node::mergeAsChild().

## ◆ build() [1/2]

void build | ( | const std::string & | filename | ) |

Populate the XML tree from an input file.

Definition at line 763 of file xml.cpp.

References XML_Node::build().

Referenced by XML_Node::build(), and Sim1D::restore().

## ◆ build() [2/2]

void build | ( | std::istream & | f,
|  | const std::string & | filename = `"[unknown]"`
| ) |  |

Main routine to create an tree-like representation of an XML file.

Given an input stream, this routine will read matched XML tags representing the ctml file until an EOF is read from the file. This routine is called by the root XML_Node object.

Parameters

  f | Input stream containing the ascii input file
  filename | Name of the input file, used in error messages

Definition at line 773 of file xml.cpp.

References XML_Node::addComment(), XML_Node::addValue(), XML_Node::attribs(), XML_Node::m_filename, XML_Reader::m_line, XML_Node::m_name, XML_Node::m_root, XML_Node::name(), XML_Node::parent(), XML_Reader::readTag(), XML_Reader::readValue(), XML_Node::root(), XML_Node::setLineNumber(), XML_Node::setName(), and Cantera::warn_deprecated().

## ◆ copyUnion()

void copyUnion | ( | XML_Node *const | node_dest | ) | const

Copy all of the information in the current XML_Node tree into the destination XML_Node tree, doing a union operation as we go.

Note this is a const function because the current XML_Node and its children isn't altered by this operation. copyUnion() doesn't duplicate existing entries in the destination XML_Node tree.

Parameters

  node_dest | This is the XML node to receive the information

Definition at line 833 of file xml.cpp.

References XML_Node::addAttribute(), XML_Node::addValue(), XML_Node::attrib(), XML_Node::children(), XML_Node::copyUnion(), XML_Node::hasAttrib(), XML_Node::m_attribs, XML_Node::m_children, XML_Node::m_iscomment, XML_Node::m_name, XML_Node::m_value, XML_Node::name(), and XML_Node::nChildren().

Referenced by XML_Node::copyUnion().

## ◆ copy()

void copy | ( | XML_Node *const | node_dest | ) | const

Copy all of the information in the current XML_Node tree into the destination XML_Node tree, doing a complete copy as we go.

Note this is a const function because the current XML_Node and its children isn't altered by this operation.

Parameters

  node_dest | This is the XML node to receive the information

Definition at line 877 of file xml.cpp.

References XML_Node::addAttribute(), XML_Node::addValue(), XML_Node::children(), XML_Node::copy(), XML_Node::m_attribs, XML_Node::m_children, XML_Node::m_linenum, XML_Node::m_name, XML_Node::m_value, XML_Node::name(), XML_Node::nChildren(), XML_Node::setLineNumber(), and XML_Node::setName().

Referenced by XML_Node::copy(), and Phase::setXMLdata().

## ◆ lock()

void lock | ( |  | ) |

Set the lock for this node and all of its children.

Definition at line 900 of file xml.cpp.

References XML_Node::m_children, and XML_Node::m_locked.

## ◆ unlock()

void unlock | ( |  | ) |

Unset the lock for this node and all of its children.

Definition at line 908 of file xml.cpp.

References XML_Node::m_children, and XML_Node::m_locked.

## ◆ write_int()

void write_int | ( | std::ostream & | s,
|  | int | level = `0`,
|  | int | numRecursivesAllowed = `60000`
| ) |  | const
| private

Write an XML subtree to an output stream.

This is the main recursive routine. It doesn't put a final endl on. This is fixed up in the public method. A method to only write out a limited amount of the XML tree has been added.

Parameters

  s | ostream to write to
  level | Indentation level to work from
  numRecursivesAllowed | Number of recursive calls allowed

Definition at line 921 of file xml.cpp.

References XML_Node::m_attribs, XML_Node::m_children, XML_Node::m_iscomment, XML_Node::m_name, XML_Node::m_value, and Cantera::npos.

Referenced by XML_Node::write().

## Member Data Documentation

## ◆ m_name

std::string m_name
| protected

XML node name of the node.

For example, if we were in the XML_Node where

     <phase dim="3" id="gas">
     </phase>

Then, this string would be equal to "phase". "dim" and "id" are attributes of the XML_Node.

Definition at line 637 of file xml.h.

Referenced by XML_Node::addValue(), XML_Node::build(), XML_Node::child(), XML_Node::copy(), XML_Node::copyUnion(), XML_Node::name(), XML_Node::setName(), and XML_Node::write_int().

## ◆ m_value

std::string m_value
| protected

Value of the XML node.

This is the string contents of the XML node. For example. The XML node named eps:

     <eps>
        valueString
     </eps>

has a m_value string containing "valueString".

Definition at line 650 of file xml.h.

Referenced by XML_Node::addValue(), XML_Node::clear(), XML_Node::copy(), XML_Node::copyUnion(), XML_Node::fp_value(), XML_Node::int_value(), XML_Node::value(), and XML_Node::write_int().

## ◆ m_filename

std::string m_filename
| protected

Name of the file from which this XML node was read.

Only populated for the root node.

Definition at line 654 of file xml.h.

Referenced by XML_Node::build(), and XML_Node::child().

## ◆ m_childindex

std::multimap<std::string, XML_Node*> m_childindex
| protected

Map containing an index between the node name and the pointer to the node.

m_childindex[node.name()] = XML_Node *pointer

This object helps to speed up searches.

Definition at line 663 of file xml.h.

Referenced by XML_Node::child(), XML_Node::clear(), XML_Node::hasChild(), XML_Node::mergeAsChild(), and XML_Node::removeChild().

## ◆ m_attribs

std::map<std::string, std::string> m_attribs
| protected

Storage of attributes for a node.

m_attribs[attribName] = attribValue

Definition at line 669 of file xml.h.

Referenced by XML_Node::addAttribute(), XML_Node::attrib(), XML_Node::attribs(), XML_Node::attribsConst(), XML_Node::clear(), XML_Node::copy(), XML_Node::copyUnion(), XML_Node::hasAttrib(), and XML_Node::write_int().

## ◆ m_parent

XML_Node* m_parent
| protected

Pointer to the parent XML_Node for the current node.

Note, the top node has a parent value of 0

Definition at line 675 of file xml.h.

Referenced by XML_Node::parent(), and XML_Node::setParent().

## ◆ m_root

XML_Node* m_root
| protected

Pointer to the root XML_Node for the current node.

Note, the top node has a root value equal to itself

Definition at line 681 of file xml.h.

Referenced by XML_Node::build(), XML_Node::root(), XML_Node::setRoot(), and XML_Node::XML_Node().

## ◆ m_locked

bool m_locked
| protected

Lock for this node.

Currently, unimplemented functionality. If locked, it means you can't delete this node.

Definition at line 688 of file xml.h.

Referenced by XML_Node::lock(), and XML_Node::unlock().

## ◆ m_children

std::vector<XML_Node*> m_children
| protected

Vector of pointers to child nodes.

Definition at line 691 of file xml.h.

Referenced by XML_Node::child(), XML_Node::children(), XML_Node::clear(), XML_Node::copy(), XML_Node::copyUnion(), XML_Node::findByAttr(), XML_Node::findByName(), XML_Node::findID(), XML_Node::findNameID(), XML_Node::findNameIDIndex(), XML_Node::lock(), XML_Node::mergeAsChild(), XML_Node::nChildren(), XML_Node::removeChild(), XML_Node::setRoot(), XML_Node::unlock(), and XML_Node::write_int().

## ◆ m_iscomment

bool m_iscomment
| protected

True if the current node is a comment node.

Definition at line 694 of file xml.h.

Referenced by XML_Node::addValue(), XML_Node::clear(), XML_Node::copyUnion(), XML_Node::isComment(), and XML_Node::write_int().

## ◆ m_linenum

int m_linenum
| protected

The member data m_linenum.

Currently, unimplemented functionality

Definition at line 700 of file xml.h.

Referenced by XML_Node::clear(), XML_Node::copy(), XML_Node::lineNumber(), and XML_Node::setLineNumber().

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

- xml.h
- xml.cpp