1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xml_parser.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _XML_PARSER_HXX_
32 #define _XML_PARSER_HXX_
37 #include <external/expat/xmlparse.h>
41 //-----------------------------------------------------
42 class xml_parser_exception
: public std::runtime_error
47 const std::string
& error_msg
,
52 std::runtime_error(error_msg
),
53 error_code_(error_code
),
54 line_number_(line_number
),
55 column_number_(column_number
),
56 byte_index_(byte_index
)
66 //-----------------------------------------------------
67 // Simple wrapper around expat, the xml parser library
68 // created by James Clark
69 //-----------------------------------------------------
70 class i_xml_parser_event_handler
;
75 //########################################################
76 xml_parser(const XML_Char
* EncodingName
= 0);
78 //########################################################
79 xml_parser(const XML_Char
* EncodingName
, XML_Char NamespaceSeparator
);
81 //########################################################
84 //########################################################
85 /** Parse a XML data stream
88 Pointer to a buffer containing the xml data
91 Length of the buffer containing the xml data
94 Indicates whether these are the last xml data
95 of an xml document to parse. For very large
96 xml documents it may be usefull to read and
97 parse the document partially.
99 @precond XmlData must not be null
102 If the used Sax parser returns an error. The SaxException
103 contains detailed information about the error. */
104 void parse(const char* XmlData
, size_t Length
, bool IsFinal
= true);
106 //########################################################
107 /** Set a document handler
109 @descr A document handler implements the interface i_xml_parser_event_handler.
110 The document handler receive notifications of various events
111 from the sax parser for instance "start_document".
113 The client is responsible for the life time management of
114 the given document handler, that means the document handler
115 instance must exist until a new one was set or until the parser
118 @param SaxDocumentHandler
119 The new document handler, may be null if not interessted in
122 @postcond currently used document handler == pSaxDocumentHandler */
123 void set_document_handler(i_xml_parser_event_handler
* event_handler
);
125 //########################################################
126 /** Returns the currently used document handler or null if
127 no document handler was set before. */
128 i_xml_parser_event_handler
* get_document_handler() const;
130 //############################################
131 void set_encoding(const XML_Char
* Encoding
);
138 i_xml_parser_event_handler
* document_handler_
;
139 XML_Parser xml_parser_
;
141 // prevent copy and assignment
143 xml_parser(const xml_parser
&);
144 xml_parser
& operator=(const xml_parser
&);