XmlDocument.hpp

Go to the documentation of this file.
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 XmlDocument.hpp
00024  * @Description Class used to parse a .xml file.
00025  * Creates a tree of XmlElement classes.
00026  * @Status Finished
00027  * @Version $Id: XmlDocument.hpp 1 2011-03-04 18:13:18Z jreis $
00028  * @Maintainer Nelson Ramos (nmsra@mega.ist.utl.pt)
00029  */
00030 
00031 #ifndef __XML_XMLDOCUMENT_H
00032 #define __XML_XMLDOCUMENT_H
00033 
00034 namespace mermaid
00035 {
00036   namespace support
00037   {
00038     namespace xml
00039     {
00040       class XmlDocument;
00041     }
00042   }
00043 }
00044 
00045 #include <libxml/parser.h>
00046 
00047 
00048 
00049 #include "XmlElement.hpp"
00050 
00051 
00052 
00053 namespace mermaid
00054 {
00055   namespace support
00056   {
00057     namespace xml
00058     {
00059       using boost::shared_ptr;
00060       
00061       /**
00062       * @Class XmlDocument XmlDocument.hpp "XmlDocument.hpp"
00063       * @Description Class representing an XML document.
00064       * @Author Marco Barbosa + Nelson Ramos
00065       */
00066       class XmlDocument
00067       {
00068         public:
00069           /**
00070           * @Description Constructor.
00071           * @Description This method creates a new XmlDocument instance.
00072           * @Author Marco Barbosa + Nelson Ramos
00073           */
00074           XmlDocument();
00075           
00076           /**
00077           * @Description Copy constructor
00078           * @Author Marco Barbosa
00079           */
00080           XmlDocument (const XmlDocument& xd);
00081           
00082           /**
00083           * Destructor.
00084           * This method makes deinitializations for objects of this class.
00085           * @Author Marco Barbosa + Nelson Ramos
00086           */
00087           ~XmlDocument();
00088           
00089           XmlDocument * clone();
00090           
00091           /**
00092           * @Description Assignment operator
00093           * @Author Marco Barbosa
00094           */
00095           XmlDocument& operator= (const XmlDocument& xd);
00096           
00097           /**
00098           * @Description Parses XML file.
00099           * @Argument name - Name of the file to be parsed.
00100           * @Argument enforceDtdValidation - if true, parsing will only be
00101           * done if file is valid according to its DTD
00102           * @throws Exception If an error occurs while parsing the file
00103           * @Author Marco Barbosa + Nelson Ramos
00104           */
00105           void parseFile (string name, bool enforceDtdValidation = true);
00106           
00107           /**
00108           * @Description Parses an XML string
00109           * @TODO Implement DTD validation
00110           * @Argument xml XML string
00111           * @throws Exception If an error occurs while parsing the string
00112           * @Author Marco Barbosa + Nelson Ramos
00113           */
00114           void parseString (string xml);
00115           
00116           /**
00117           * Get the root element of the document.
00118           * @Returns bool TRUE if successful, FALSE otherwise.
00119           * @Author Marco Barbosa + Nelson Ramos
00120           */
00121           shared_ptr<XmlElement> getRootElement();
00122           
00123           /**
00124           * Checks if the document is well formed.
00125           * @Returns bool TRUE if document is well formed, FALSE otherwise.
00126           * @Author Marco Barbosa
00127           */
00128           bool isWellFormed();
00129           
00130           /**
00131           * Checks if the document is valid.
00132           * @Returns bool TRUE if document is valid, FALSE otherwise.
00133           * @Author Marco Barbosa
00134           */
00135           bool isValid();
00136           
00137           //! @TODO implement operator==
00138           
00139         private:
00140           bool isWellFormed_;
00141           bool isValid_;
00142           shared_ptr<XmlElement> rootElement_;
00143           
00144           void copyFrom (const XmlDocument& xd);
00145           void cleanUp();
00146       }; // class XmlDocument
00147     } // namespace xml
00148   } // namespace support
00149 } // namespace mermaid
00150 
00151 #endif // __XML_XMLDOCUMENT_H
Generated on Fri Mar 4 22:14:58 2011 for MeRMaID::support by  doxygen 1.6.3