diff --git a/Cantera/src/base/xml.cpp b/Cantera/src/base/xml.cpp index 24db7a7cb..9596ee2dc 100755 --- a/Cantera/src/base/xml.cpp +++ b/Cantera/src/base/xml.cpp @@ -380,6 +380,11 @@ namespace Cantera { m_childindex.erase(node->name()); } + std::string XML_Node::id() const { + if (hasAttrib("id")) return attrib("id"); + return std::string(""); + } + /** * This routine carries out a search for an XML node based * on both the xml element name and the attribute ID. @@ -467,6 +472,19 @@ namespace Cantera { return 0; } + const XML_Node* XML_Node::findByName(const string& nm) const { + if (name() == nm) { + return this; + } + const XML_Node* r = 0; + int n = nChildren(); + for (int i = 0; i < n; i++) { + r = m_children[i]->findByName(nm); + if (r != 0) return r; + } + return 0; + } + /** * addChild(string name, string value): * diff --git a/Cantera/src/base/xml.h b/Cantera/src/base/xml.h index 11dea6318..5440d4e79 100755 --- a/Cantera/src/base/xml.h +++ b/Cantera/src/base/xml.h @@ -61,13 +61,13 @@ namespace Cantera { class XML_Node { public: - XML_Node(std::string nm = "--", XML_Node* p = 0, int n = 0); + XML_Node(std::string nm = "--", XML_Node* p = 0, int n = 0); XML_Node(const XML_Node &right); XML_Node& operator=(const XML_Node &right); - virtual ~XML_Node(); + virtual ~XML_Node(); void addComment(std::string comment); XML_Node& addChild(XML_Node& node); XML_Node& addChild(std::string name); @@ -142,11 +142,15 @@ namespace Cantera { * The name is the XML node is the XML node name */ std::string name() const { return m_name; } - std::string id() const { - if (hasAttrib("id")) return attrib("id"); - else return ""; - } - int number() const { return m_n; } + + //! Return the id attribute, if present + /*! + * Returns the id attribute if present. If not + * it return the empty string + */ + std::string id() const; + + int number() const { return m_n; } XML_Node& child(int n) const { return *m_children[n]; } std::vector& children() { return m_children; } @@ -175,6 +179,7 @@ namespace Cantera { XML_Node* findID(const std::string& id, int depth=100) const; XML_Node* findByAttr(const std::string& attr, const std::string& val); + const XML_Node* findByName(const std::string& nm) const; XML_Node* findByName(const std::string& nm); void getChildren(std::string name, std::vector& children) const; XML_Node& child(std::string loc) const;