Statistics
| Branch: | Revision:

root / src / nedxml / nedsaxhandler.cc @ 68da4f12

History | View | Annotate | Download (2.47 KB)

1 01873262 Georg Kunz
//==========================================================================
2
//  NEDSAXHANDLER.CC - part of
3
//
4
//                     OMNeT++/OMNEST
5
//            Discrete System Simulation in C++
6
//
7
//==========================================================================
8
9
/*--------------------------------------------------------------*
10
  Copyright (C) 2002-2008 Andras Varga
11
  Copyright (C) 2006-2008 OpenSim Ltd.
12

13
  This file is distributed WITHOUT ANY WARRANTY. See the file
14
  `license' for details on this and other legal matters.
15
*--------------------------------------------------------------*/
16
17
18
#include "nedsaxhandler.h"
19
#include "nedelements.h"
20
#include "nederror.h"
21
#include "nedexception.h"
22
23
USING_NAMESPACE
24
25
26
NEDSAXHandler::NEDSAXHandler(const char *fname, NEDErrorStore *e)
27
{
28
    root = current = 0;
29
    sourcefilename = fname;
30
    errors = e;
31
}
32
33
NEDSAXHandler::~NEDSAXHandler()
34
{
35
    delete root;
36
}
37
38
NEDElement *NEDSAXHandler::getTree()
39
{
40
    NEDElement *tree = root;
41
    root = current = 0;
42
    return tree;
43
}
44
45
void NEDSAXHandler::startElement(const char *name, const char **atts)
46
{
47
    // initialize node
48
    NEDElement *node;
49
    bool unknown = false;
50
    try {
51
        node = NEDElementFactory::getInstance()->createElementWithTag(name);
52
    }
53
    catch (NEDException& e) {
54
        errors->addError(current, "error: %s", e.what());
55
        node = new UnknownElement();
56
        node->setAttribute("element", name);
57
    }
58
59
    // "debug info"
60
    char buf[200];
61
    sprintf(buf,"%s:%d",sourcefilename, parser->getCurrentLineNumber());
62
    node->setSourceLocation(buf);
63
64
    // set attributes
65
    if (!unknown)
66
    {
67
        for (int i=0; atts && atts[i]; i+=2) {
68
            try {
69
                node->setAttribute(atts[i], atts[i+1]);
70
            }
71
            catch (NEDException& e) {
72
                errors->addError(node, "error in attribute '%s': %s", atts[i], e.what());
73
            }
74
        }
75
    }
76
77
    // add to tree
78
    if (!root) {
79
        root = current = node;
80
    } else {
81
        current->appendChild(node);
82
        current = node;
83
    }
84
}
85
86
void NEDSAXHandler::endElement(const char *name)
87
{
88
    current = current->getParent();
89
}
90
91
void NEDSAXHandler::characterData(const char *s, int len)
92
{
93
    // ignore
94
}
95
96
void NEDSAXHandler::processingInstruction(const char *target, const char *data)
97
{
98
    // ignore
99
}
100
101
void NEDSAXHandler::comment(const char *data)
102
{
103
    // ignore
104
}
105
106
void NEDSAXHandler::startCdataSection()
107
{
108
    // ignore
109
}
110
111
void NEDSAXHandler::endCdataSection()
112
{
113
    // ignore
114
}