NorMIT-nav  18.04
An IGT application
cxXmlFileHandler.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 
13 #include "cxXmlFileHandler.h"
14 #include "cxLogger.h"
15 #include <QFile>
16 #include <QTextStream>
17 
18 
19 namespace cx
20 {
21 
22 QDomDocument XmlFileHandler::readXmlFile(QString& filename)
23 {
24  QDomDocument retval;
25  QFile file(filename);
26  if (!file.open(QIODevice::ReadOnly))
27  {
28  reportError("Could not open XML file :" + file.fileName() + ".");
29  return QDomDocument();
30  }
31 
32  QString emsg;
33  int eline, ecolumn;
34  // Read the file
35  if (!retval.setContent(&file, false, &emsg, &eline, &ecolumn))
36  {
37  reportError("Could not parse XML file :" + file.fileName() + " because: " + emsg + "");
38  return QDomDocument();
39  }
40 
41  return retval;
42 }
43 
44 void XmlFileHandler::writeXmlFile(QDomDocument& doc, QString& filename)
45 {
46  QFile file(filename);
47  if (file.open(QIODevice::WriteOnly | QIODevice::Truncate))
48  {
49  QTextStream stream(&file);
50  stream << doc.toString(4);
51  file.close();
52  }
53  else
54  {
55  reportError("Could not open " + file.fileName() + " Error: " + file.errorString());
56  }
57 }
58 
59 
60 
61 } // namespace cx
static void writeXmlFile(QDomDocument &doc, QString &filename)
void reportError(QString msg)
Definition: cxLogger.cpp:71
static QDomDocument readXmlFile(QString &filename)
Namespace for all CustusX production code.