/*************************************************************************** * GXml.cpp - XML class * * ----------------------------------------------------------------------- * * copyright (C) 2010-2013 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see . * * * ***************************************************************************/ /** * @file GXml.cpp * @brief XML class implementation * @author Juergen Knoedlseder */ /* __ Includes ___________________________________________________________ */ #ifdef HAVE_CONFIG_H #include #endif #include "GUrlFile.hpp" #include "GUrlString.hpp" #include "GXml.hpp" #include "GXmlNode.hpp" #include "GXmlDocument.hpp" #include "GXmlText.hpp" #include "GXmlElement.hpp" #include "GXmlComment.hpp" #include "GXmlPI.hpp" #include "GException.hpp" #include "GTools.hpp" /* __ Method name definitions ____________________________________________ */ #define G_LOAD "GXml::load(std::string&)" #define G_PARSE "GXml::parse(GUrl&)" #define G_PROCESS "GXml::process(GXmlNode*, const std::string&)" /* __ Macros _____________________________________________________________ */ /* __ Coding definitions _________________________________________________ */ /* __ Debug definitions __________________________________________________ */ /*========================================================================== = = = Constructors/destructors = = = ==========================================================================*/ /***********************************************************************//** * @brief Void constructor ***************************************************************************/ GXml::GXml(void) { // Initialise members init_members(); // Return return; } /***********************************************************************//** * @brief Copy constructor * * @param[in] xml XML object. ***************************************************************************/ GXml::GXml(const GXml& xml) { // Initialise members init_members(); // Copy members copy_members(xml); // Return return; } /***********************************************************************//** * @brief XML document constructor * * @param[in] xml XML text string or file name. * * Constructs GXml object by either parsing a text string or a file. If the * @p xml argument starts with @p ') { segment.append(1, (char)c); throw GException::xml_syntax_error(G_PARSE, segment, "unexpected closing bracket \">\" encountered"); } // ... otherwise add character to segment else { segment.append(1, (char)c); } } // If we are within a markup and if a markup end is reached then process // the markup and switch to not in_tag mode else { // Markup stop reached? if (c == '>') { // Append character to segment segment.append(1, (char)c); // If we are in comment then check if this is the end of // the comment if (in_comment) { int n = segment.length(); if (n > 2) { if (segment.compare(n-3,3,"-->") == 0) { in_comment = false; } } } // If we are not in the comment, then process markup if (!in_comment) { // Process markup process_markup(¤t, segment); // Prepare new segment and signal that we are not // within markup segment.clear(); in_markup = false; } } // Markup start encountered? else if (!in_comment && c == '<') { // Append character to segment segment.append(1, (char)c); // If we encounter an opening bracket then throw an exception throw GException::xml_syntax_error(G_PARSE, segment, "unexpected opening bracket \"<\" encountered"); } // ... otherwise add character to segment else { segment.append(1, (char)c); if (!in_comment && segment == "") == 0)) { type = MT_COMMENT; } // Check for declaration else if (n >= 7 && (segment.compare(0,6,"") == 0)) { type = MT_DECLARATION; } // Check for processing instruction else if (n >= 4 && (segment.compare(0,2,"") == 0)) { type = MT_PROCESSING; } // Check for empty element tag else if (n >= 3 && (segment.compare(0,1,"<") == 0) && (segment.compare(n-2,2,"/>") == 0)) { type = MT_ELEMENT_EMPTY; } // Check for element end tag else if (n >= 3 && (segment.compare(0,2,"") == 0)) { type = MT_ELEMENT_END; } // Check for element start tag else if (n >= 2 && (segment.compare(0,1,"<") == 0) && (segment.compare(n-1,1,">") == 0)) { type = MT_ELEMENT_START; } // Return type return type; }