Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
easydom.cpp
Go to the documentation of this file.
1 /*
2  * Vega Strike
3  * Copyright (C) 2001-2002 Daniel Horn
4  *
5  * http://vegastrike.sourceforge.net/
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */
21 
22 /*
23  * easyDom - easy DOM for expat - written by Alexander Rawass <alexannika@users.sourceforge.net>
24  */
25 
26 #include <expat.h>
27 #include "easydom.h"
28 
29 #include <assert.h>
30 
31 using std::cout;
32 using std::cerr;
33 using std::endl;
35 
36 void easyDomNode::set( easyDomNode *_parent, string _name, const XML_Char **atts )
37 {
38  parent = _parent;
39  if (atts != NULL) {
40  for (; *atts != NULL; atts += 2) {
41 #if 0
42  att_name.push_back( (*iter).name );
43  att_value.push_back( (*iter).value );
44 #endif
45  attribute_map[atts[0]] = atts[1];
46  }
47  }
48  name = _name;
49 }
50 
52 {
53  subnodes.push_back( child );
54 }
55 
56 string easyDomNode::attr_value( string search_name )
57 {
58  return attribute_map[search_name];
59 }
60 
61 void easyDomNode::printNode( ostream &out, int recurse_level, int level )
62 {
63  vsUMap< string, string >::const_iterator iter;
64 
65  out<<"<"<<name;
66  for (iter = attribute_map.begin(); iter != attribute_map.end(); iter++)
67  out<<" "<<(*iter).first<<"=\""<<(*iter).second<<"\"";
68  out<<">"<<endl;
69 
70  vector< easyDomNode* >::const_iterator siter;
71  if (recurse_level > 0)
72  for (siter = subnodes.begin(); siter != subnodes.end(); siter++)
73  (*siter)->printNode( out, recurse_level-1, level+1 );
74  if ( !(recurse_level == 0 && level == 0) )
75  out<<"</"<<name<<">"<<endl;
76 }
77 
78 const char *textAttr = "Text_Attr";
79