/**
 * File: contextxmlparser.h
 * Created by: <Joern Reimerdes>
 * Created on: 2004/08/31 13:48:00
 * @file
 * $Id$
 * $Revision$
 * $Author$
 * $Date$
 *
 * This file is a part of The iWear Framework.
 * In particular is this file a part of the Framework context Library
 *
 * The iWear Framework 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 as in version 2 of the License.

 * 
 * The iWear Framework 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
 * The iWear Framework; if not, write to the Free Software Foundation, Inc., 59
 * Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __XML_HANDLER_H_
#define __XML_HANDLER_H_

#include <string>
#include <iwear/debugstream.h>
#include <iwear_utils_xml/iweardomerrorhandler.h>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/util/PlatformUtils.hpp>

#include <iostream>

using namespace std;
using namespace xercesc;

namespace iwear{ 
namespace xml{ 

/** The XMLHandler is used to provide basic functions to work with XML Files.
 * To handle XML it uses Xerces for C++.
 */
class XMLHandler
{
public:
	
    /** Creates a new XMLHandler.
     * 
     */
    XMLHandler();

    /** Destroys the XMLHandler and the DOMBuilder.
     * This will destroy all DOMDocuments created by the Parser.
     */
    ~XMLHandler();
    
    /** Reads an XML File.
     * @note DOMValidation includes namespaces and datatype normalisation
     *  validation. The validation can be switched of.
     * @param string uri URI of the file that should be loaded.
     * @param bool validate Specifies whether to use DOMValidation or
     * not. (Default is true.)
     * @return DOMDocument The document element. NULL will be returned
     * if there was an error reading the document.
     */
    DOMDocument* load_dom_document_from_file(string uri, bool validate = true);

    /** Gets all DOMElements of a specified Name.
     * @param DOMElement* parent The node above the searched elements.
     * @param const XMLCh* node_name The name of the searched nodes.
     * @return list<DOMElement*>* A list of all nodes with the
     *  searched name. NULL if no node is found.
     */
    list<DOMElement*>* 
    get_element_list_by_name(DOMElement* parent, const XMLCh* node_name);

    /** Gets the first DOMElement with a specified name.
     * @param DOMElement* parent The node above the searched element.
     * @param const XMLCh* node_name The name of the searched node.
     * @return DOMElement* The searched node and NULL if no node is found.
     */
    DOMElement* 
    get_first_element_by_name(DOMElement* parent, const XMLCh* node_name);
        
    /** Writes an XML File.
     * @param string content The XML string that should be written to a file.
     * @param string uri URI of the file that should be loaded.
     * @return DOMDocument The document element.
     */
    void write_document(string content, string uri);

protected:

    DOMBuilder* dom_builder;

}; // ContextXMLParser
}  // context
}  // iwear

#endif	//__XML_HANDLER_H_

