]> git.mxchange.org Git - flightgear.git/blob - src/Network/http/SimpleDOM.cxx
Interim windows build fix
[flightgear.git] / src / Network / http / SimpleDOM.cxx
1 #include "SimpleDOM.hxx"
2 using std::string;
3
4 namespace flightgear {
5 namespace http {
6
7 DOMNode::~DOMNode()
8 {
9   for( Children_t::const_iterator it = _children.begin(); it != _children.end(); ++it )
10     delete *it;
11 }
12
13 string DOMNode::render() const
14 {
15   string reply;
16   reply.append( "<" ).append( _name );
17   for( Attributes_t::const_iterator it = _attributes.begin(); it != _attributes.end(); ++it ) {
18     reply.append( " " );
19     reply.append( it->first );
20     reply.append( "=\"" );
21     reply.append( it->second );
22     reply.append( "\"" );
23   }
24
25   if( _children.empty() ) {
26     reply.append( " />\r" );
27     return reply;
28   } else {
29     reply.append( ">" );
30   }
31
32   for( Children_t::const_iterator it = _children.begin(); it != _children.end(); ++it ) {
33     reply.append( (*it)->render() );
34   }
35
36   reply.append( "</" ).append( _name ).append( ">\r" );
37
38   return reply;
39 }
40
41 DOMNode * DOMNode::addChild( DOMElement * child )
42 {
43   _children.push_back( child );
44   return dynamic_cast<DOMNode*>(child);
45 }
46
47 DOMNode * DOMNode::setAttribute( const string & name, const string & value )
48 {
49   _attributes[name] = value;
50   return this;
51 }
52
53 }
54 }