00001 /*
00002 * (C) Copyright 2002, Schlund+Partner AG
00003 *
00004 * This library is free software; you can redistribute it and/or
00005 * modify it under the terms of the GNU Lesser General Public
00006 * License as published by the Free Software Foundation; either
00007 * version 2.1 of the License, or (at your option) any later version.
00008 *
00009 * This library is distributed in the hope that it will be useful,
00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00012 * Lesser General Public License for more details.
00013 *
00014 * You should have received a copy of the GNU Lesser General Public
00015 * License along with this library; if not, write to the Free Software
00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00017 */
00018
00031 #ifndef SP_GXML_XMLNODE_HPP
00032 #define SP_GXML_XMLNODE_HPP
00033
00034 // STDC++
00035 #include <string>
00036
00037 // C libraries
00038 #include <libxslt/xsltInternals.h>
00039 #include <libxml/xpath.h>
00040 #include <libxml/tree.h>
00041
00042 namespace SP {
00043 namespace GXML {
00044
00045 class XMLNode
00046 {
00047 public:
00048 XMLNode();
00049 XMLNode( const xmlNodePtr node );
00050 ~XMLNode();
00051
00052 enum Exceptions
00053 {
00054 NO_NODE=1, // NodePtr is NULL
00055 LAST_NODE, // node has no following sibling
00056 FIRST_NODE, // node has no preceding sibling
00057 DOC_NODE, // node is document node (has no parent)
00058 NO_CHILD, // node has no children
00059 NO_CONTENT, // node has no content (no child text-node)
00060 NO_ATTRIBUTES, // node has no attributes
00061 NO_VALUE // attribute has no value (should never happen)
00062 };
00063 // XMLTree getDoc(); makes no sense till there is a doc-object
00065 // hint:
00066 // EVERY group of spcaes or characters is contained within a invisible
00067 // text-node.
00068 // i.e. <node/> <node/> expands to <node/><text> </text><node/>
00069 // return next node in order (every space between tags is a text node!)
00070 // throws LAST_NODE if no following sibling exists
00071 XMLNode getNext();
00072 // return previous node in order
00073 // throws FIRST_NODE if no preceding sibling exists
00074 XMLNode getPrev();
00075 // return parent of current node
00076 // throws DOC_NODE if no parent exists
00077 XMLNode getParent();
00078 // return first child of node (text-node if node has content)
00079 // throws
00080 XMLNode getChild();
00081 // return last child of node
00082 XMLNode getLast();
00083
00084 // return node type (i.e. XML_ELEMENT_NODE, XML_ATTRIBUTE_NODE,
00085 // XML_TEXT_NODE, ... )
00086 int getType();
00087 // return name of node-tag
00088 std::string getName();
00089 // return content of node (which is the content of the first child text-node)
00090 std::string getContent();
00091 // return attribute value by name
00092 std::string getAttribute( const std::string& name );
00093 // XMLAttributeSet getAttributeSet( XMLNode* node );
00094
00095 // returns XML subtree of node
00096 std::string getNodeDump();
00097
00098 xmlNodePtr getNodePtr();
00099
00100 private:
00101 xmlNodePtr node_;
00102 };
00103
00104 }}
00105 #endif
1.2.15