diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
commit | 8362bf63dea22bbf6736609b0f49c152f975eb63 (patch) | |
tree | 0eea3928e39e50fae91d4e68b21b1e6cbae25604 /lib/kofficecore/KoDom.h | |
download | koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip |
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'lib/kofficecore/KoDom.h')
-rw-r--r-- | lib/kofficecore/KoDom.h | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/kofficecore/KoDom.h b/lib/kofficecore/KoDom.h new file mode 100644 index 00000000..4d95a42b --- /dev/null +++ b/lib/kofficecore/KoDom.h @@ -0,0 +1,70 @@ +/* This file is part of the KDE project + Copyright (C) 2004 David Faure <faure@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef KODOM_H +#define KODOM_H + +#include <qdom.h> +#include <koffice_export.h> +/** + * This namespace contains a few convenience functions to simplify code using QDom + * (when loading OASIS documents, in particular). + * + * To find the child element with a given name, use KoDom::namedItemNS. + * + * To find all child elements with a given name, use + * QDomElement e; + * forEachElement( e, parent ) + * { + * if ( e.localName() == "..." && e.namespaceURI() == KoXmlNS::... ) + * { + * ... + * } + * } + * Note that this means you don't ever need to use QDomNode nor toElement anymore! + * Also note that localName is the part without the prefix, this is the whole point + * of namespace-aware methods. + * + * To find the attribute with a given name, use QDomElement::attributeNS. + * + * Do not use getElementsByTagNameNS, it's recursive (which is never needed in KOffice). + * Do not use tagName() or nodeName() or prefix(), since the prefix isn't fixed. + * + * @author David Faure <faure@kde.org> + */ +namespace KoDom { + + /** + * A namespace-aware version of QDomNode::namedItem(), + * which also takes care of casting to a QDomElement. + * Use this when a domelement is known to have only *one* child element + * with a given tagname. + * + * Note: do *NOT* use getElementsByTagNameNS, it's recursive! + */ + KOFFICECORE_EXPORT QDomElement namedItemNS( const QDomNode& node, const char* nsURI, const char* localName ); + +} + +#define forEachElement( elem, parent ) \ + for ( QDomNode _node = parent.firstChild(); !_node.isNull(); _node = _node.nextSibling() ) \ + if ( !( elem = _node.toElement() ).isNull() ) + +#endif /* KODOM_H */ + |