kspread/latex/export/xmlparser.cpp
1/*
2** A program to convert the XML rendered by KOffice into LATEX.
3**
4** Copyright (C) 2000-2002 Robert JACOLIN
5**
6** This library is free software; you can redistribute it and/or
7** modify it under the terms of the GNU Library General Public
8** License as published by the Free Software Foundation; either
9** version 2 of the License, or (at your option) any later version.
10**
11** This library is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14** Library General Public License for more details.
15**
16** To receive a copy of the GNU Library General Public License, write to the
17** Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19**
20*/
21
22#include <kdebug.h>
23#include <KoStore.h>
24
25#include "xmlparser.h"
26#include "tqfile.h"
27
28/* Init static data */
29FileHeader* XmlParser::_fileHeader = 0;
30Document* XmlParser::_root = 0;
31KoStore* XmlParser::_in = NULL;
32
33XmlParser::XmlParser(TQString filename): _filename(filename)
34{
35 TQFile f(filename);
36 if(!f.open(IO_ReadOnly))
37 return;
38 if(!_document.setContent(&f))
39 {
40 f.close();
41 return;
42 }
43 f.close();
44 //_eltCurrent = _document.documentElement();
45}
46
47XmlParser::XmlParser(TQByteArray in)
48{
49 _document.setContent(in);
50}
51
52XmlParser::XmlParser(const KoStore* in)
53{
54 _in = const_cast<KoStore*>(in);
55 if(!_in->open("root"))
56 {
57 kdError(30522) << "Unable to open input file!" << endl;
58 return;
59 }
60 /* input file Reading */
61 TQByteArray array = _in->read(_in->size());
62 _document.setContent(array);
63}
64
65XmlParser::XmlParser()
66{
67}
68
69XmlParser::~XmlParser()
70{
71 if(_in != NULL)
72 _in->close();
73}
74
75TQDomNode XmlParser::getChild(TQDomNode balise, TQString name)
76{
77 TQDomNode node = getChild(balise, name, 0);
78 kdDebug(30522) << node.nodeName() << endl;
79 return node;
80}
81
82bool XmlParser::isChild(TQDomNode balise, TQString name)
83{
84 if(balise.isElement())
85 return balise.toElement().elementsByTagName(name).count();
86 return false;
87}
88
89TQDomNode XmlParser::getChild(TQDomNode balise, TQString name, int index)
90{
91 if(balise.isElement()) {
92 TQDomNodeList children = balise.toElement().elementsByTagName(name);
93 if ( children.count() )
94 return children.item(index);
95 }
96 return TQDomNode();
97}
98
99TQDomNode XmlParser::getChild(TQDomNode balise, int index)
100{
101 TQDomNodeList children = balise.childNodes();
102 if ( children.count() )
103 return children.item(index);
104 return TQDomNode();
105}
106
107TQString XmlParser::getData(TQDomNode balise, int index)
108{
109 return getChild(getChild(balise, index), 0).nodeValue();
110}
111
112TQString XmlParser::getData(TQDomNode balise, TQString name)
113{
114 return getChild(getChild(balise, name), 0).nodeValue();
115}
116
117int XmlParser::getNbChild(TQDomNode balise)
118{
119 return balise.childNodes().count();
120}
121
122int XmlParser::getNbChild(TQDomNode balise, TQString name)
123{
124 if(balise.isElement())
125 return balise.toElement().elementsByTagName(name).count();
126 return -1;
127}
128
129TQString XmlParser::getChildName(TQDomNode balise, int index)
130{
131 return balise.childNodes().item(index).nodeName();
132}
133
134TQString XmlParser::getAttr(TQDomNode balise, TQString name) const
135{
136 if(balise.isElement())
137 return balise.toElement().attributeNode(name).value();
138 return TQString();
139}
This class hold a whole document with its headers, footers, footnotes, endnotes, content,...
This class hold all general information about the doc : does it use a color markup,...