Syndication

atomtools.cpp
1 /*
2  This file is part of the syndication library
3  SPDX-FileCopyrightText: 2006 Frank Osterfeld <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "constants.h"
9 #include "tools.h"
10 
11 #include <syndication/elementwrapper.h>
12 #include <syndication/tools.h>
13 
14 #include <QDomElement>
15 #include <QString>
16 
17 namespace Syndication
18 {
19 namespace Atom
20 {
21 QString extractAtomText(const Syndication::ElementWrapper &parent, const QString &tagname)
22 {
23  QString str;
24 
25  QDomElement el = parent.firstElementByTagNameNS(atom1Namespace(), tagname);
26 
27  bool isCDATA = el.firstChild().isCDATASection();
28 
29  QString type = el.attribute(QStringLiteral("type"), QStringLiteral("text"));
30 
31  if (type == QLatin1String("text")) {
32  str = parent.extractElementTextNS(atom1Namespace(), tagname).trimmed();
33  if (isCDATA) {
34  str = resolveEntities(str);
35  }
36 
37  str = escapeSpecialCharacters(str);
38  } else if (type == QLatin1String("html")) {
39  str = parent.extractElementTextNS(atom1Namespace(), tagname).trimmed();
40  } else if (type == QLatin1String("xhtml")) {
41  str = ElementWrapper::childNodesAsXML(el).trimmed();
42  }
43 
44  return str;
45 }
46 
47 } // namespace Atom
48 } // namespace Syndication
QDomNode firstChild() const const
QString trimmed() const const
bool isCDATASection() const const
QString atom1Namespace()
namespace used by Atom 1.0 elements
QString extractAtomText(const Syndication::ElementWrapper &parent, const QString &tagname)
extracts the content of an atomTextConstruct.
Definition: atomtools.cpp:21
QString attribute(const QString &name, const QString &defValue) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 03:57:11 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.