Subversion Repositories gelsvn

Rev

Rev 540 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 540 Rev 595
Line -... Line 1...
-
 
1
/* ----------------------------------------------------------------------- *
-
 
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
-
 
3
 * Copyright (C) the authors and DTU Informatics
-
 
4
 * For license and list of authors, see ../../doc/intro.pdf
-
 
5
 * ----------------------------------------------------------------------- */
-
 
6
 
1
#include <fstream>
7
#include <fstream>
2
#include <string>
8
#include <string>
3
#include <sstream>
9
#include <sstream>
4
#include <cstring>
10
#include <cstring>
5
#include <algorithm>
11
#include <algorithm>
6
#include <list>
12
#include <list>
-
 
13
 
7
#include "XmlParser.h"
14
#include "XmlParser.h"
8
#include "string_utils.h"
15
#include "string_utils.h"
9
 
16
 
10
using namespace std;
-
 
11
 
-
 
12
namespace Util
17
namespace Util
13
{
18
{
-
 
19
    using std::string;
-
 
20
    using std::map;
-
 
21
    using std::list;
-
 
22
    using std::pair;
-
 
23
    
-
 
24
    using std::ifstream;
-
 
25
    using std::ostream;
-
 
26
    using std::ostringstream;
-
 
27
    using std::ios_base;
-
 
28
    
-
 
29
    using std::max;
-
 
30
    
-
 
31
    using std::cerr;
-
 
32
    using std::endl;
-
 
33
    
14
  /////////////////////////////////////////////////////////////////
34
    /////////////////////////////////////////////////////////////////
15
  // String handling
35
    // String handling
16
  /////////////////////////////////////////////////////////////////
36
    /////////////////////////////////////////////////////////////////
17
 
37
    
18
  void parse_attribs(const string& s, map<string, string>& result)
38
    void parse_attribs(const string& s, map<string, string>& result)
Line 110... Line 130...
110
  {
130
    {
111
    seek_string(in, "<");
131
        seek_string(in, "<");
112
 
132
        
113
    string head;
133
        string head;
114
    read_until(in, head, ">");
134
        read_until(in, head, ">");
115
 
-
 
116
    if(head.empty() || head[0] == '!') return in;
135
        if(head.empty() || head[0] == '!') return in;
117
    if(head[0] == '/')
136
        if(head[0] == '/')
118
    {
137
        {
119
      if(elem.parent && elem.parent->name == head.substr(1))
138
            if(elem.parent && elem.parent->name == head.substr(1))
120
        in.setstate(ios_base::eofbit);
139
                in.setstate(ios_base::eofbit);
Line 122... Line 141...
122
        elem.name = "";
141
                elem.name = "";
123
      return in;
142
            return in;
124
    }
143
        }
125
 
144
        
126
    bool has_body = true;
145
        bool has_body = true;
-
 
146
        
127
    if(head[head.size() - 1] == '/')
147
        if(head[head.size() - 1] == '/')
128
    {
148
        {
129
      has_body = false;
149
            has_body = false;
130
      head.erase(head.size() - 1);
150
            head.erase(head.size() - 1);
131
    }
151
        }
Line 208... Line 228...
208
    body.element.doc = this;
228
        body.element.doc = this;
209
  }
229
    }
210
 
230
    
211
  void XmlDoc::process_elements()
231
    void XmlDoc::process_elements()
212
  {
232
    {
213
    while((infile >> body.element) && !infile.eof())
233
        while(!infile.eof() && (infile >> body.element))
214
    {
234
        {
215
      XmlElementHandler h = handlers[body.element.name];
235
            XmlElementHandler h = handlers[body.element.name];
216
      if(h) 
236
            if(h)
217
        h(body.element);
237
                h(body.element);
218
      else 
238
            else