Initial import into git.
[galago.git] / cpp / galago / contrib / indri / src / XMLNode.cpp
blobc100d8392e9a31eab03621b19a1e46abe86ab99b
1 /*==========================================================================
2 * Copyright (c) 2004 University of Massachusetts. All Rights Reserved.
4 * Use of the Lemur Toolkit for Language Modeling and Information Retrieval
5 * is subject to the terms of the software license set forth in the LICENSE
6 * file included with this software, and also available at
7 * http://www.lemurproject.org/license.html
9 *==========================================================================
14 // XMLNode
16 // 8 October 2003 - tds
19 #include "indri/XMLNode.hpp"
21 indri::xml::XMLNode::XMLNode( const std::string& name ) : _name(name)
25 indri::xml::XMLNode::XMLNode( const std::string& name, const std::string& value ) : _name(name), _value(value)
29 indri::xml::XMLNode::XMLNode( const std::string& name, const MAttributes& attributes ) : _name(name), _attributes(attributes)
33 indri::xml::XMLNode::XMLNode( const std::string& name, const MAttributes& attributes, const std::string& value ) : _name(name), _attributes(attributes), _value(value)
37 indri::xml::XMLNode::~XMLNode() {
38 for( unsigned int i=0; i<_children.size(); i++ )
39 delete _children[i];
42 void indri::xml::XMLNode::addChild( XMLNode* child ) {
43 _children.push_back(child);
46 void indri::xml::XMLNode::addAttribute( const std::string& key, const std::string& value ) {
47 _attributes.insert( std::make_pair( key, value ) );
50 const std::string& indri::xml::XMLNode::getName() const {
51 return _name;
54 const std::string& indri::xml::XMLNode::getValue() const {
55 return _value;
58 const indri::xml::XMLNode::MAttributes& indri::xml::XMLNode::getAttributes() const {
59 return _attributes;
62 std::string indri::xml::XMLNode::getAttribute( const std::string& name ) const {
63 MAttributes::const_iterator iter;
64 iter = _attributes.find( name );
66 if( iter != _attributes.end() ) {
67 return iter->second;
70 return std::string();
73 const std::vector<indri::xml::XMLNode*>& indri::xml::XMLNode::getChildren() const {
74 return _children;
77 const indri::xml::XMLNode* indri::xml::XMLNode::getChild( const std::string& name ) const {
78 for( unsigned int i=0; i<_children.size(); i++ ) {
79 if( _children[i]->getName() == name )
80 return _children[i];
83 return 0;
86 std::string indri::xml::XMLNode::getChildValue( const std::string& name ) const {
87 const indri::xml::XMLNode* child = getChild(name);
89 if( child ) {
90 return child->getValue();
93 return std::string();
96 void indri::xml::XMLNode::setValue( const std::string& value ) {
97 _value = value;