SVN_SILENT made messages (.desktop file)
[kdeaccessibility.git] / kttsd / filters / xhtml2ssml / xmlelement.cpp
blobf9673caea1119234b9a678cfe7e95ae71d44ce92
1 /****************************************************************************
2 XMLElement class
4 Representation of an XML element with methods for getting/setting
5 attributes and generating "opening" and "closing" tags.
6 -------------------
7 Copyright:
8 (C) 2004 by Paul Giannaros <ceruleanblaze@gmail.com>
9 -------------------
10 Original author: Paul Giannaros <ceruleanblaze@gmail.com>
11 ******************************************************************************/
13 /***************************************************************************
14 * *
15 * This program is free software; you can redistribute it and/or modify *
16 * it under the terms of the GNU General Public License as published by *
17 * the Free Software Foundation; version 2 of the License. *
18 * *
19 ***************************************************************************/
21 #include "xmlelement.h"
22 #include <iostream>
24 /// Constructors
25 XMLElement::XMLElement() {
26 m_name = "";
27 m_attrmapper = AttributeToValueMap();
29 XMLElement::XMLElement(const QString &name) {
30 m_name = name;
31 m_attrmapper = AttributeToValueMap();
33 /// Destructor
34 XMLElement::~XMLElement() {
35 return;
38 /// Copy constructor
39 XMLElement::XMLElement(const XMLElement &element) {
40 m_attrmapper = element.m_attrmapper;
41 m_name = element.m_name;
44 /// Assignement operator
45 XMLElement XMLElement::operator=(const XMLElement &element) {
46 m_attrmapper = element.m_attrmapper;
47 m_name = element.m_name;
48 return *this;
51 QString XMLElement::name() {
52 return m_name;
54 QString XMLElement::startTag() {
55 QString output = '<' + m_name + ' ';
56 for(AttributeToValueMap::Iterator it = m_attrmapper.begin(); it != m_attrmapper.end(); ++it) {
57 output.append(it.key() + "=\"" + it.data() + "\" ");
59 output = output.left(output.length() - 1);
60 // Get rid of the space at the end and then append a '>'
61 output.append(">");
62 return output;
65 QString XMLElement::endTag() {
66 return "</" + m_name + '>';
69 void XMLElement::setAttribute(const QString &attr, const QString &value) {
70 m_attrmapper[attr] = value;
72 QString XMLElement::attribute(const QString &attr) {
73 return m_attrmapper[attr];
76 QString XMLElement::toQString() {
77 QString tag = startTag();
78 return tag.left(tag.length() - 1).right(tag.length() - 2);
81 XMLElement XMLElement::fromQString(const QString &str) {
82 QStringList sections = str.split( " ");
83 QString tagname = sections[0];
84 XMLElement e(tagname.latin1());
86 sections.pop_front();
87 // Loop over the remaining strings which are attributes="values"
88 if(sections.count()) {
89 const int sectionsCount = sections.count();
90 for(int i = 0; i < sectionsCount; ++i) {
91 QStringList list = sections[i].split( "=");
92 if(list.count() != 2) {
93 std::cerr << "XMLElement::fromQString: Cannot convert list: " << list.join("|") << ". `" << str << "' is not in valid format.\n";
94 return XMLElement(" ");
96 e.setAttribute(list[0], list[1].left(list[1].length() - 1).right(list[1].length() -2));
99 return e;