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 // XMLParser.h: interface for the XMLParser class. 00024 // 00025 ////////////////////////////////////////////////////////////////////// 00026 00027 #if !defined(AFX_XMLPARSER_H__CD17EC42_A9BE_450C_BB84_C94D55772665__INCLUDED_) 00028 #define AFX_XMLPARSER_H__CD17EC42_A9BE_450C_BB84_C94D55772665__INCLUDED_ 00029 00030 #if _MSC_VER > 1000 00031 #pragma once 00032 #endif // _MSC_VER > 1000 00033 00034 #include "standard.h" 00035 // #include <fstream> 00036 #include <stdio.h> 00037 // #include "include/cc++/url.h" 00038 #include "Debug.h" // Added by ClassView 00039 #include "JString.h" // Added by ClassView 00040 #include "Object.h" 00041 #include "ObjectCollection.h" // Added by ClassView 00042 #include "XMLNode.h" 00043 #include "JFile.h" 00044 00045 namespace cmlabs { 00046 00047 // class XMLParser : public Object, URLStream, ifstream 00048 class XMLParser : public Object //, std::ifstream 00049 { 00050 public: 00051 bool parseURL(const JString& url); 00052 void setXmlUrl(const JString& url); 00053 XMLParser(); 00054 XMLParser(char url[]); 00055 virtual ~XMLParser(); 00056 Object* clone() const {return NULL;} 00057 00058 void deleteAllNodes(); 00059 00060 bool parse(); 00061 bool parse(const JString& s); 00062 bool parseXML(const JString& s); 00063 JString verifyXML(const JString& xml); 00064 JString getErrorString(); 00065 00066 // Convenient relay methods for xmlNode 00067 ObjectCollection getAllNodes(const JString& childPath) const; 00068 XMLNode* getNodeWithAttrValue(Collection& attrPath, const JString& attrValue) const; 00069 ObjectCollection* getChildTags(); 00070 00071 XMLNode* getChildNode(const JString& childPath) const; 00072 XMLNode* getChildNode(Collection& childPath) const; 00073 00074 ObjectCollection getChildNodes(const JString& childPath) const; 00075 ObjectCollection getChildNodes(Collection& childPath) const; 00076 00077 JString findAttr(const JString& attr) const; 00078 // JString findAttr(Collection& attrPath) const; 00079 Dictionary* getAttributes(); 00080 00081 JString asXML(); 00082 JString asXMLWithCRs(); 00083 00084 bool isUTF(); 00085 00086 XMLNode* getRootNode() const; 00087 void setRootNode(XMLNode* node); 00088 00089 bool unitTest(); 00090 00091 bool getXmlUrl() const; 00092 00093 bool parseComments; 00094 00095 private: 00096 bool parseLine(const JString& s); 00097 bool addXMLAttrAndValue(const JString& attr, const JString& value); 00098 bool addXMLNode(const JString& s, int line, int col); 00099 bool addXMLCommentNode(const JString& s, int line, int col); 00100 bool addXMLDirectiveNode(const JString& s, int line, int col); 00101 00102 JString trimLeadingWhite(char *s) const; 00103 void printNodeStack(char *s); 00104 void reset(); 00105 00106 void pushNode(XMLNode* node); 00107 XMLNode* popNode(); 00108 00109 int line; 00110 int tagDepth; 00111 JString currLine; 00112 JString xml; 00113 XMLNode* xmlNode; 00114 XMLNode* currNode; 00115 00116 ObjectCollection nodeStack; 00117 00118 JString buf; 00119 JString attr; 00120 JString tag; 00121 00122 bool singleQuoteOpen; 00123 bool doubleQuoteOpen; 00124 bool attrTag; 00125 bool tagOpen; 00126 bool tagClose; 00127 bool commentOpen; 00128 bool isCloseComment(const JString& s) const; 00129 00130 bool isXMLUTF; 00131 JString xmlUrl; 00132 00133 JString errorString; 00134 }; 00135 00136 } // namespace cmlabs 00137 00138 #endif // !defined(AFX_XMLPARSER_H__CD17EC42_A9BE_450C_BB84_C94D55772665__INCLUDED_)