• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeaccessibility API Reference
  • KDE Home
  • Contact Us
 

jovie

  • sources
  • kde-4.12
  • kdeaccessibility
  • jovie
  • filters
  • xhtml2ssml
xmlelement.cpp
Go to the documentation of this file.
1 /****************************************************************************
2  XMLElement class
3 
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 
12  This program is free software; you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation; either version 2 of the License, or
15  (at your option) version 3.
16 
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25  ***************************************************************************/
26 
27 #include "xmlelement.h"
28 #include <iostream>
29 
31 XMLElement::XMLElement() {
32  m_name = "";
33  m_attrmapper = AttributeToValueMap();
34 }
35 XMLElement::XMLElement(const QString &name) {
36  m_name = name;
37  m_attrmapper = AttributeToValueMap();
38 }
40 XMLElement::~XMLElement() {
41  return;
42 }
43 
45 XMLElement::XMLElement(const XMLElement &element) {
46  m_attrmapper = element.m_attrmapper;
47  m_name = element.m_name;
48 }
49 
51 XMLElement XMLElement::operator=(const XMLElement &element) {
52  m_attrmapper = element.m_attrmapper;
53  m_name = element.m_name;
54  return *this;
55 }
56 
57 QString XMLElement::name() {
58  return m_name;
59 }
60 QString XMLElement::startTag() {
61  QString output = '<' + m_name + ' ';
62  for(AttributeToValueMap::Iterator it = m_attrmapper.begin(); it != m_attrmapper.end(); ++it) {
63  output.append(it.key() + "=\"" + it.data() + "\" ");
64  }
65  output = output.left(output.length() - 1);
66  // Get rid of the space at the end and then append a '>'
67  output.append(">");
68  return output;
69 }
70 
71 QString XMLElement::endTag() {
72  return "</" + m_name + '>';
73 }
74 
75 void XMLElement::setAttribute(const QString &attr, const QString &value) {
76  m_attrmapper[attr] = value;
77 }
78 QString XMLElement::attribute(const QString &attr) {
79  return m_attrmapper[attr];
80 }
81 
82 QString XMLElement::toQString() {
83  QString tag = startTag();
84  return tag.left(tag.length() - 1).right(tag.length() - 2);
85 }
86 
87 XMLElement XMLElement::fromQString(const QString &str) {
88  QStringList sections = str.split( ' ');
89  QString tagname = sections[0];
90  XMLElement e(tagname.latin1());
91 
92  sections.pop_front();
93  // Loop over the remaining strings which are attributes="values"
94  if(sections.count()) {
95  const int sectionsCount = sections.count();
96  for(int i = 0; i < sectionsCount; ++i) {
97  QStringList list = sections[i].split( '=');
98  if(list.count() != 2) {
99  std::cerr << "XMLElement::fromQString: Cannot convert list: " << list.join("|") << ". `" << str << "' is not in valid format.\n";
100  return XMLElement(" ");
101  }
102  e.setAttribute(list[0], list[1].left(list[1].length() - 1).right(list[1].length() -2));
103  }
104  }
105  return e;
106 }
107 
XMLElement::attribute
QString attribute(const QString &attr)
Get the value of an attribute.
Definition: xmlelement.cpp:78
XMLElement::operator=
XMLElement operator=(const XMLElement &element)
Assignment operator.
Definition: xmlelement.cpp:51
XMLElement::~XMLElement
~XMLElement()
Destructor.
Definition: xmlelement.cpp:40
XMLElement
Definition: xmlelement.h:35
XMLElement::XMLElement
XMLElement()
Constructors.
Definition: xmlelement.cpp:31
XMLElement::endTag
QString endTag()
Get a textual representation of the closed tag that XMLElement represents.
Definition: xmlelement.cpp:71
XMLElement::toQString
QString toQString()
Convert to a QString.
Definition: xmlelement.cpp:82
XMLElement::startTag
QString startTag()
Get a textual representation of the starting of the tag with all attributes and their values set out...
Definition: xmlelement.cpp:60
XMLElement::fromQString
static XMLElement fromQString(const QString &str)
Create an XMLElement from a QString.
Definition: xmlelement.cpp:87
XMLElement::name
QString name()
Get the name of the tag (the text between the greater than and less than symbols).
Definition: xmlelement.cpp:57
xmlelement.h
XMLElement::setAttribute
void setAttribute(const QString &attr, const QString &value)
Create an attribute and set its value.
Definition: xmlelement.cpp:75
AttributeToValueMap
QMap< QString, QString > AttributeToValueMap
Definition: xmlelement.h:31
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:32:25 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

jovie

Skip menu "jovie"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeaccessibility API Reference

Skip menu "kdeaccessibility API Reference"
  • jovie

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal