00001 /***************************** License ********************************** 00002 00003 Copyright (C) 2008 by Communicative Machines 00004 http://www.cmlabs.com All rights reserved. 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2.1 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public 00017 License along with this library; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 00020 ************************************************************************/ 00021 00022 00023 // XMLNode.h: interface for the XMLNode class. 00024 // 00025 ////////////////////////////////////////////////////////////////////// 00026 00027 #if !defined(AFX_XMLNODE_H__DE034BFC_CE07_424E_8385_13977121E936__INCLUDED_) 00028 #define AFX_XMLNODE_H__DE034BFC_CE07_424E_8385_13977121E936__INCLUDED_ 00029 00030 #if _MSC_VER > 1000 00031 #pragma once 00032 #endif // _MSC_VER > 1000 00033 00034 #include "Object.h" 00035 #include "JString.h" 00036 #include "Dictionary.h" 00037 #include "Collection.h" 00038 #include "ObjectCollection.h" 00039 00040 #define JSTRINGNULL JString("") 00041 #define ISJSTRINGNULL(js) (js == JSTRINGNULL) 00042 00043 namespace cmlabs { 00044 00045 class XMLNode : public Object 00046 { 00047 public: 00048 XMLNode* getNodeWithAttrValue(Collection& attrPath, const JString& attrValue); 00049 XMLNode(const JString& s); 00050 Object* clone() const; 00051 00052 void deleteAllChildNodes(); 00053 00054 JString asXMLChildrenOnly(); 00055 JString asXMLWithCRs(); 00056 JString toXML(); 00057 JString toXMLChildrenOnly(); 00058 JString toHTML(); 00059 00060 JString asXMLOpenTag(); 00061 JString asXMLCloseTag(); 00062 00063 Collection getPath() const; 00064 00065 XMLNode * getParent() const; 00066 void setParent(XMLNode* p); 00067 00068 ObjectCollection* getChildTags(); 00069 ObjectCollection getAllNodes(const JString& childPath); 00070 00071 XMLNode* getFirstChildNode(); 00072 XMLNode* getChildNode(const JString& childPath); 00073 XMLNode* getChildNode(Collection& childPath); 00074 00075 ObjectCollection getChildNodes(const JString& childPath); 00076 ObjectCollection getChildNodes(Collection& childPath); 00077 00078 JString findAttr(const JString& attr) const; 00079 // JString findAttr(Collection& attrPath) const; 00080 Dictionary* getAttributes(); 00081 //! Checks for attribute attr in tag <tag attr="xxx" /> 00082 bool hasAttribute(const JString& attr) const; 00083 //! Returns the attribute value in tag <tag attr="xxx" /> 00084 JString getAttribute(const JString& attr) const; 00085 00086 //! Returns text content, if content is XML returns "" (use getTextContent() then) 00087 JString getText() const; 00088 void setText(const JString& t); 00089 //! Returns text content even if content is XML format 00090 JString getTextContent(); 00091 00092 bool isEmpty() const; 00093 00094 bool setComment(const JString& t); 00095 bool setPreComment(const JString& t); 00096 bool setPostComment(const JString& t); 00097 JString getComment() const; 00098 JString getPreComment() const; 00099 JString getPostComment() const; 00100 bool isCommentNode() const; 00101 00102 bool setDirective(const JString& t); 00103 JString getDirective() const; 00104 bool isDirectiveNode() const; 00105 00106 void setTag(const JString& t); 00107 JString getTag() const; 00108 00109 XMLNode(); 00110 virtual ~XMLNode(); 00111 00112 bool isUTF(); 00113 00114 // Adding attributes and child tags 00115 void addAttribute(const JString& attr, const JString& attrValue); 00116 void addChildTag(Object* childValue); 00117 00118 // Formatting XML as JString 00119 JString indent(int nestLevel); 00120 JString asXML(int nestLevel, bool withCRs); 00121 JString asXML(); 00122 00123 XMLNode* parent; 00124 JString tag; 00125 JString text; 00126 // ####### expensive to create and destroy ######### 00127 Dictionary* attributes; 00128 ObjectCollection* childTags; 00129 JString preComment; 00130 JString postComment; 00131 JString directive; 00132 00133 bool isXMLUTF; 00134 int lineno; 00135 int charno; 00136 }; 00137 00138 #define XMLNODE(n) ((XMLNode*) n) 00139 #define XMLNODENULL XMLNODE(NULL) 00140 00141 } // namespace cmlabs 00142 00143 #endif // !defined(AFX_XMLNODE_H__DE034BFC_CE07_424E_8385_13977121E936__INCLUDED_)