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

Syndication Library

  • Syndication
  • ElementWrapper
Public Member Functions | Static Public Member Functions | List of all members
Syndication::ElementWrapper Class Reference

#include <elementwrapper.h>

Public Member Functions

 ElementWrapper ()
 
 ElementWrapper (const ElementWrapper &other)
 
 ElementWrapper (const QDomElement &element)
 
virtual ~ElementWrapper ()
 
QString attribute (const QString &name, const QString &defValue=QString()) const
 
QString attributeNS (const QString &nsURI, const QString &localName, const QString &defValue=QString()) const
 
QString childNodesAsXML () const
 
QString completeURI (const QString &uri) const
 
const QDomElement & element () const
 
QList< QDomElement > elementsByTagName (const QString &tagName) const
 
QList< QDomElement > elementsByTagNameNS (const QString &nsURI, const QString &tagName) const
 
QString extractElementText (const QString &tagName) const
 
QString extractElementTextNS (const QString &namespaceURI, const QString &localName) const
 
QDomElement firstElementByTagNameNS (const QString &nsURI, const QString &tagName) const
 
bool hasAttribute (const QString &name) const
 
bool hasAttributeNS (const QString &nsURI, const QString &localName) const
 
bool isNull () const
 
ElementWrapper & operator= (const ElementWrapper &other)
 
bool operator== (const ElementWrapper &other) const
 
QString text () const
 
QString xmlBase () const
 
QString xmlLang () const
 

Static Public Member Functions

static QString childNodesAsXML (const QDomElement &parent)
 

Detailed Description

A wrapper for XML elements.

This is the base class for the (lazy) wrappers used in the RSS2 and Atom parsers. The wrapped element can be accessed via element(). It also contains several helper functions for XML processing.

Author
Frank Osterfeld

Definition at line 43 of file elementwrapper.h.

Constructor & Destructor Documentation

Syndication::ElementWrapper::ElementWrapper ( )

creates a element wrapper wrapping a null element.

isNull() will return true for these instances.

Definition at line 47 of file elementwrapper.cpp.

Syndication::ElementWrapper::ElementWrapper ( const ElementWrapper &  other)

Copy constructor.The instances share the same element.

Parameters
otherthe element wrapper to copy

Definition at line 53 of file elementwrapper.cpp.

Syndication::ElementWrapper::ElementWrapper ( const QDomElement &  element)

Creates an element wrapper wrapping the DOM element element.

Parameters
elementthe element to wrap

Definition at line 58 of file elementwrapper.cpp.

Syndication::ElementWrapper::~ElementWrapper ( )
virtual

destructor

Definition at line 66 of file elementwrapper.cpp.

Member Function Documentation

QString Syndication::ElementWrapper::attribute ( const QString &  name,
const QString &  defValue = QString() 
) const

Returns the attribute called name.

If the attribute does not exist defValue is returned. (which is a null string by default).

Parameters
nametag name
defValuethe default value

Definition at line 279 of file elementwrapper.cpp.

QString Syndication::ElementWrapper::attributeNS ( const QString &  nsURI,
const QString &  localName,
const QString &  defValue = QString() 
) const

Returns the attribute with the local name localName and the namespace URI nsURI.

If the attribute does not exist defValue is returned (which is a null string by default).

Parameters
nsURInamespace URI
localNamelocal tag name
defValuethe default value

Definition at line 284 of file elementwrapper.cpp.

QString Syndication::ElementWrapper::childNodesAsXML ( ) const

returns the child nodes of the wrapped element as XML.

See childNodesAsXML(const QDomElement& parent) for details

Returns
XML serialization of the wrapped element's children

Definition at line 217 of file elementwrapper.cpp.

QString Syndication::ElementWrapper::childNodesAsXML ( const QDomElement &  parent)
static

concatenates the XML representations of all children.

Example: If parent is an xhtml:body element like

<xhtml:body><p>foo</p><blockquote>bar</blockquote></xhtml:body>

this function returns

<p>foo</p><blockquote>bar</blockquote>

namespace and xml:base information are preserved.

Parameters
parentthe DOM element whose children should be returned as XML
Returns
XML serialization of parent's children

Definition at line 185 of file elementwrapper.cpp.

QString Syndication::ElementWrapper::completeURI ( const QString &  uri) const

completes relative URIs with a prefix specified via xml:base.

Example:

xml:base="http://www.foo.org/", uri="announcements/bar.html"

is completed to http://www.foo.org/announcements/bar.html

See also xmlBase().

Parameters
uria possibly relative URI
Returns
the resolved, absolute URI (using xml:base), if uri is a relative, valid URI. If uri is not valid, absolute, or no xml:base is set in the scope of this element, uri is returned unmodified.

Definition at line 137 of file elementwrapper.cpp.

const QDomElement & Syndication::ElementWrapper::element ( ) const

returns the wrapped resource.

Definition at line 86 of file elementwrapper.cpp.

QList< QDomElement > Syndication::ElementWrapper::elementsByTagName ( const QString &  tagName) const

returns all child elements with tag name tagName Contrary to QDomElement::elementsByTagName() only direct descendents are returned.

Parameters
tagNamethe tag name of the elements to extract
Returns
a list of child elements with the given tag name

Definition at line 222 of file elementwrapper.cpp.

QList< QDomElement > Syndication::ElementWrapper::elementsByTagNameNS ( const QString &  nsURI,
const QString &  tagName 
) const

returns all child elements with tag name tagname and namespace URI nsURI.

Contrary to QDomElement::elementsByTagNameNS() only direct descendents are returned

Parameters
nsURIthe namespace URI
tagNamethe local name (local within its namespace) of the element to search for
Returns
a list of child elements with the given namespace URI and tag name

Definition at line 256 of file elementwrapper.cpp.

QString Syndication::ElementWrapper::extractElementText ( const QString &  tagName) const

extracts the text from a child element, ignoring namespaces.

For instance, when the wrapped element is <thisElement>:

<thisElement>
<title>Hi there</title>
</thisElement>

extractElementText("title") will return the text content of title, "Hi there".

Parameters
tagNamethe name of the element to extract
Returns
the (trimmed) text content of tagName, or a null string if there is no such tag

Definition at line 173 of file elementwrapper.cpp.

QString Syndication::ElementWrapper::extractElementTextNS ( const QString &  namespaceURI,
const QString &  localName 
) const

extracts the text from a child element, respecting namespaces.

If there is more than one child with the same tag name, the first one is processed. For instance, when the wrapped element is <hisElement>:

<thisElement>
<atom:title>Hi there</atom:title>
</thisElement>
extractElementText("http://www.w3.org/2005/Atom", "title")

will return the text content of atom:title, "Hi there". (Assuming that "atom" is defined as "http://www.w3.org/2005/Atom")

Parameters
namespaceURIthe namespace URI of the element to extract
localNamethe local name (local within its namespace) of the element to extract
Returns
the (trimmed) text content of localName, or a null string if there is no such tag

Definition at line 179 of file elementwrapper.cpp.

QDomElement Syndication::ElementWrapper::firstElementByTagNameNS ( const QString &  nsURI,
const QString &  tagName 
) const

searches the direct children of the wrapped element for an element with a given namespace and tag name.

Parameters
nsURIthe namespace URI
tagNamethe local name (local within its namespace) of the element to search for
Returns
the first child element with the given namespace URI and tag name, or a null element if no such element was found.

Definition at line 237 of file elementwrapper.cpp.

bool Syndication::ElementWrapper::hasAttribute ( const QString &  name) const

Returns true if this element has an attribute called name; otherwise returns false.

Parameters
namethe attribute name (without namespace)

Definition at line 289 of file elementwrapper.cpp.

bool Syndication::ElementWrapper::hasAttributeNS ( const QString &  nsURI,
const QString &  localName 
) const

Returns true if this element has an attribute with the local name localName and the namespace URI nsURI; otherwise returns false.

Parameters
nsURInamespace URI
localNamelocal attribute name

Definition at line 294 of file elementwrapper.cpp.

bool Syndication::ElementWrapper::isNull ( ) const

returns whether the wrapped element is a null element

Returns
true if isNull() is true for the wrapped element, false otherwise

Definition at line 81 of file elementwrapper.cpp.

ElementWrapper & Syndication::ElementWrapper::operator= ( const ElementWrapper &  other)

Assigns another element wrapper to this one.

Both instances share the same wrapped element instance.

Parameters
otherthe element wrapper to assign
Returns
reference to this instance

Definition at line 70 of file elementwrapper.cpp.

bool Syndication::ElementWrapper::operator== ( const ElementWrapper &  other) const

compares two wrappers.

Two wrappers are equal if and only if the wrapped elements are equal.

Parameters
otheranother element wrapper to compare to

Definition at line 76 of file elementwrapper.cpp.

QString Syndication::ElementWrapper::text ( ) const

Returns the wrapped element's text or an empty string.

For more information, see QDomElement::text();

Definition at line 274 of file elementwrapper.cpp.

QString Syndication::ElementWrapper::xmlBase ( ) const

returns the xml:base value to be used for the wrapped element.

The xml:base attribute establishes the base URI for resolving any relative references found in its scope (its own element and all descendants). (See also completeURI())

Returns
the xml:base value, or a null string if not set

Definition at line 91 of file elementwrapper.cpp.

QString Syndication::ElementWrapper::xmlLang ( ) const

returns the xml:lang value to be used for the wrapped element.

The xml:lang attribute indicates the natural language for its element and all descendants.

Returns
the xml:lang value, or a null string if not set

Definition at line 147 of file elementwrapper.cpp.


The documentation for this class was generated from the following files:
  • elementwrapper.h
  • elementwrapper.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:37:32 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Syndication Library

Skip menu "Syndication Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

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