00001 /* 00002 Copyright 2007, 2008, 2009, 2010, 2011 Instituto de Sistemas e Robotica, Instituto Superior Tecnico 00003 00004 This file is part of MeRMaID. 00005 00006 MeRMaID is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU Lesser General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 MeRMaID 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 00014 GNU Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public License 00017 along with MeRMaID. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 00021 00022 /** 00023 * @Filename XmlElement.hpp 00024 * @Description XmlElement class definition. 00025 * @Status Implementing 00026 * @Version $Id: XmlElement.hpp 1 2011-03-04 18:13:18Z jreis $ 00027 * @Maintainer Nelson Ramos (nmsra@mega.ist.utl.pt) 00028 */ 00029 00030 #ifndef __XML_XMLELEMENT_H_ 00031 #define __XML_XMLELEMENT_H_ 00032 00033 namespace mermaid 00034 { 00035 namespace support 00036 { 00037 namespace xml 00038 { 00039 class XmlElement; 00040 } 00041 } 00042 } 00043 00044 #include <vector> 00045 00046 #include <libxml/parser.h> 00047 00048 #include "XmlAttribute.hpp" 00049 #include "XmlAttributeVector.hpp" 00050 #include "XmlCharData.hpp" 00051 #include "XmlElementVector.hpp" 00052 #include "XmlItem.hpp" 00053 00054 00055 00056 namespace mermaid 00057 { 00058 namespace support 00059 { 00060 namespace xml 00061 { 00062 using std::string; 00063 00064 /** 00065 * @Class XmlElement XmlElement.hpp "XmlElement.hpp" 00066 * @Description Class representing an XML Element. 00067 * @Author Marco Barbosa 00068 */ 00069 class XmlElement : public XmlItem 00070 { 00071 friend class XmlDocument; 00072 00073 public: 00074 /** 00075 * @Description Constructor. 00076 * @Description This method creates a new XmlElement instance. 00077 * @Author Marco Barbosa 00078 */ 00079 XmlElement(); 00080 00081 /** 00082 * @Description Copy constructor 00083 * @Author Marco Barbosa 00084 */ 00085 XmlElement (const XmlElement& e); 00086 00087 /** 00088 * @Description Constructor. 00089 * @Description This method build an XmlElement from a string 00090 * @Author Marco Barbosa 00091 */ 00092 XmlElement (string xmlString); 00093 00094 /** 00095 * @Description Destructor. 00096 * @Description This method makes deinitializations for objects 00097 * of this class. 00098 * @Author Marco Barbosa 00099 */ 00100 ~XmlElement(); 00101 00102 virtual XmlElement * clone(); 00103 00104 /** 00105 * @Description Assignment operator 00106 * @Author Marco Barbosa 00107 */ 00108 XmlElement& operator= (const XmlElement& e); 00109 00110 /** 00111 * XmlElement's name getter. 00112 * @Returns string Returns the name of this element. 00113 * @Author Marco Barbosa 00114 */ 00115 const string getName() const; 00116 00117 /** 00118 * XmlElement's CharData getter. 00119 * @Returns XmlCharDataVector Returns all the CharData belonging 00120 * to this element 00121 * @Author Marco Barbosa 00122 */ 00123 XmlCharDataVector getCharData(); 00124 00125 /** 00126 * XmlElement's CharData getter. 00127 * @Returns XmlCharDataVector Returns only the first CharData 00128 * which is not blank 00129 * @Author Marco Barbosa 00130 */ 00131 shared_ptr<XmlCharData> getFirstNonBlankCharData(); 00132 00133 /** 00134 * XmlElement's children elements getter. 00135 * @Returns XmlElementVector Ret urns all the child elements. 00136 * @Author Marco Barbosa 00137 */ 00138 XmlElementVector getChildrenElements(); 00139 00140 /** 00141 * XmlElement's attribute getter. 00142 * @Returns XmlAttributeVector Returns all the attributes. 00143 * @Author Marco Barbosa 00144 */ 00145 const XmlAttributeVector getAttributes() const; 00146 00147 /** 00148 * @Description Method to convert value to string 00149 */ 00150 virtual operator string() const; 00151 00152 /** 00153 * @Description Method to check if XmlItem is of type XmlElement 00154 * @Returns True 00155 */ 00156 virtual const bool isXmlElement() const; 00157 00158 protected: 00159 00160 private: 00161 /** 00162 * Constructor. 00163 * This method creates a new XmlElement instance. 00164 * @Argument node libxml2 node pointer. 00165 * @Author Marco Barbosa 00166 */ 00167 XmlElement (xmlNodePtr node); 00168 00169 void buildFromLibxml2Node (xmlNodePtr node); 00170 00171 void copyFrom (const XmlElement& e); 00172 void cleanUp(); 00173 00174 string name_; 00175 XmlCharDataVector charData_; 00176 XmlElementVector childrenElements_; 00177 XmlAttributeVector attributes_; 00178 XmlItemVector items_; 00179 }; // class XmlElement 00180 } // namespace xml 00181 } // namespace support 00182 } // namespace mermaid 00183 00184 #endif // __XML_XMLELEMENT_H_