00001
00013 #ifndef XMLNODE_H_
00014 #define XMLNODE_H_
00015
00016 #include <iostream>
00017 #include <vector>
00018 #include <map>
00019 #include <stack>
00020
00021 namespace sxml
00022 {
00023
00024 using namespace std;
00025
00026 class XmlNode;
00027
00032 typedef enum {
00033 eBadStream,
00034
00035 eUtf8BomError,
00036 eXmlParseError,
00037 eMissingCloseTag,
00038 eUnexpectedCloseTag,
00039 eUnexpectedEof,
00040
00041 eUnknownNodeType,
00042 eNodeIncomplete
00043 } Exception;
00044
00048 typedef enum {
00049 ntUndefined,
00050 ntDocumentNode,
00051 ntDocTypeNode,
00052 ntCommentNode,
00053 ntElementNode,
00054 ntTextNode
00055 } NodeType;
00056
00060 class NodeSearch
00061 {
00062 private:
00063 XmlNode* owner;
00064 bool ignoreNamespaces;
00065 stack<XmlNode*> parents;
00066 stack<int> childIndices;
00067
00068 string name;
00069
00070 friend class XmlNode;
00071 };
00072
00073 typedef map<string, string> NodeAttributes;
00074 typedef map<string, string>::iterator NodeAttributesIterator;
00075 typedef vector<XmlNode*> NodeChildren;
00076 typedef vector<XmlNode*>::iterator NodeChildrenIterator;
00077
00081 class XmlNode
00082 {
00083 public:
00084 NodeType type;
00085 string name;
00086 bool complete;
00087
00088 NodeAttributes attributes;
00089 NodeChildren children;
00090
00091 XmlNode();
00092 XmlNode(const NodeType type, const string& name);
00093 virtual ~XmlNode();
00094
00095 void freeSubTree();
00096
00097 void readFromStream(istream& readFrom, const bool readChildren = true);
00098 void writeToStream(ostream& writeTo, const bool pretty = true);
00099
00100 NodeSearch* findInit(const string& name, const bool ignoreNamespaces = false);
00101 XmlNode* findNext(NodeSearch* ns);
00102 void findFree(NodeSearch* ns);
00103
00104 XmlNode* findFirst(const string& name, const bool ignoreNamespaces = false);
00105 };
00106
00107 }
00108
00109 #endif