2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = glib-Simple-XML-Subset-Parser.html
28 * strct = GMarkupParseContext
39 * - g_markup_parse_context_
48 * - GDataset* -> Dataset
53 module glib
.SimpleXML
;
59 import tango
.io
.Stdout
; // use the tango loging?
63 private import gtkc
.glibtypes
;
65 private import gtkc
.glib
;
68 private import glib
.ErrorG
;
69 private import glib
.Dataset
;
70 private import glib
.Str
;
77 * The "GMarkup" parser is intended to parse a simple markup format
78 * that's a subset of XML. This is a small, efficient, easy-to-use
79 * parser. It should not be used if you expect to interoperate with other
80 * applications generating full-scale XML. However, it's very useful for
81 * application data files, config files, etc. where you know your
82 * application will be the only one writing the file. Full-scale XML
83 * parsers should be able to parse the subset used by GMarkup, so you can
84 * easily migrate to full-scale XML at a later time if the need arises.
85 * GMarkup is not guaranteed to signal an error on all invalid XML; the
86 * parser may accept documents that an XML parser would not. However, XML
87 * documents which are not well-formed[4] are not considered valid GMarkup
89 * Simplifications to XML include:
90 * Only UTF-8 encoding is allowed.
91 * No user-defined entities.
92 * Processing instructions, comments and the doctype declaration are "passed
93 * through" but are not interpreted in any way.
94 * No DTD or validation.
95 * The markup format does support:
98 * 5 standard entities: amp; lt; gt; quot; apos;
99 * Character references
100 * Sections marked as CDATA
102 public class SimpleXML
105 /** the main Gtk struct */
106 protected GMarkupParseContext
* gMarkupParseContext
;
109 public GMarkupParseContext
* getSimpleXMLStruct()
111 return gMarkupParseContext
;
115 /** the main Gtk struct as a void* */
116 protected void* getStruct()
118 return cast(void*)gMarkupParseContext
;
122 * Sets our main struct and passes it to the parent class
124 public this (GMarkupParseContext
* gMarkupParseContext
)
128 if ( gMarkupParseContext
is null )
133 Stdout("struct gMarkupParseContext is null on constructor").newline
;
137 printf("struct gMarkupParseContext is null on constructor");
144 assert(gMarkupParseContext
!is null, "struct gMarkupParseContext is null on constructor");
146 this.gMarkupParseContext
= gMarkupParseContext
;
158 * Escapes text so that the markup parser will parse it verbatim.
159 * Less than, greater than, ampersand, etc. are replaced with the
160 * corresponding entities. This function would typically be used
161 * when writing out a file to be parsed with the markup parser.
162 * Note that this function doesn't protect whitespace and line endings
163 * from being processed according to the XML rules for normalization
164 * of line endings and attribute values.
166 * some valid UTF-8 text
168 * length of text in bytes, or -1 if the text is nul-terminated
170 * a newly allocated string with the escaped text
172 public static char[] gMarkupEscapeText(char[] text
, int length
)
174 // gchar* g_markup_escape_text (const gchar *text, gssize length);
175 return Str
.toString(g_markup_escape_text(Str
.toStringz(text
), length
) );
179 * Formats arguments according to format, escaping
180 * all string and character arguments in the fashion
181 * of g_markup_escape_text(). This is useful when you
182 * want to insert literal strings into XML-style markup
183 * output, without having to worry that the strings
184 * might themselves contain markup.
185 * const char *store = "Fortnum Mason";
186 * const char *item = "Tea";
188 * output = g_markup_printf_escaped ("<purchase>"
189 * "<store>%s</store>"
194 * printf() style format string
196 * the arguments to insert in the format string
198 * newly allocated result from formatting
199 * operation. Free with g_free().
202 public static char[] gMarkupPrintfEscaped(char[] format
, ... )
204 // gchar* g_markup_printf_escaped (const char *format, ...);
205 return Str
.toString(g_markup_printf_escaped(Str
.toStringz(format
)) );
209 * Formats the data in args according to format, escaping
210 * all string and character arguments in the fashion
211 * of g_markup_escape_text(). See g_markup_printf_escaped().
213 * printf() style format string
215 * variable argument list, similar to vprintf()
217 * newly allocated result from formatting
218 * operation. Free with g_free().
221 public static char[] gMarkupVprintfEscaped(char[] format
, void* args
)
223 // gchar* g_markup_vprintf_escaped (const char *format, va_list args);
224 return Str
.toString(g_markup_vprintf_escaped(Str
.toStringz(format
), args
) );
228 * Signals to the GMarkupParseContext that all data has been
229 * fed into the parse context with g_markup_parse_context_parse().
230 * This function reports an error if the document isn't complete,
231 * for example if elements are still open.
233 * a GMarkupParseContext
235 * return location for a GError
237 * TRUE on success, FALSE if an error was set
239 public int endParse(GError
** error
)
241 // gboolean g_markup_parse_context_end_parse (GMarkupParseContext *context, GError **error);
242 return g_markup_parse_context_end_parse(gMarkupParseContext
, error
);
246 * Frees a GMarkupParseContext. Can't be called from inside
247 * one of the GMarkupParser functions.
249 * a GMarkupParseContext
253 // void g_markup_parse_context_free (GMarkupParseContext *context);
254 g_markup_parse_context_free(gMarkupParseContext
);
258 * Retrieves the current line number and the number of the character on
259 * that line. Intended for use in error messages; there are no strict
260 * semantics for what constitutes the "current" line number other than
261 * "the best number we could come up with for error messages."
263 * a GMarkupParseContext
265 * return location for a line number, or NULL
267 * return location for a char-on-line number, or NULL
269 public void getPosition(int* lineNumber
, int* charNumber
)
271 // void g_markup_parse_context_get_position (GMarkupParseContext *context, gint *line_number, gint *char_number);
272 g_markup_parse_context_get_position(gMarkupParseContext
, lineNumber
, charNumber
);
276 * Retrieves the name of the currently open element.
278 * a GMarkupParseContext
280 * the name of the currently open element, or NULL
283 public char[] getElement()
285 // const gchar* g_markup_parse_context_get_element (GMarkupParseContext *context);
286 return Str
.toString(g_markup_parse_context_get_element(gMarkupParseContext
) );
290 * Creates a new parse context. A parse context is used to parse
291 * marked-up documents. You can feed any number of documents into
292 * a context, as long as no errors occur; once an error occurs,
293 * the parse context can't continue to parse text (you have to free it
294 * and create a new parse context).
298 * one or more GMarkupParseFlags
300 * user data to pass to GMarkupParser functions
302 * user data destroy notifier called when the parse context is freed
304 * a new GMarkupParseContext
306 public this (GMarkupParser
* parser
, GMarkupParseFlags flags
, void* userData
, GDestroyNotify userDataDnotify
)
308 // GMarkupParseContext* g_markup_parse_context_new (const GMarkupParser *parser, GMarkupParseFlags flags, gpointer user_data, GDestroyNotify user_data_dnotify);
309 this(cast(GMarkupParseContext
*)g_markup_parse_context_new(parser
, flags
, userData
, userDataDnotify
) );
313 * Feed some data to the GMarkupParseContext. The data need not
314 * be valid UTF-8; an error will be signaled if it's invalid.
315 * The data need not be an entire document; you can feed a document
316 * into the parser incrementally, via multiple calls to this function.
317 * Typically, as you receive data from a network connection or file,
318 * you feed each received chunk of data into this function, aborting
319 * the process if an error occurs. Once an error is reported, no further
320 * data may be fed to the GMarkupParseContext; all errors are fatal.
322 * a GMarkupParseContext
324 * chunk of text to parse
326 * length of text in bytes
328 * return location for a GError
330 * FALSE if an error occurred, TRUE on success
331 * [4] XML specification
333 public int parse(char[] text
, int textLen
, GError
** error
)
335 // gboolean g_markup_parse_context_parse (GMarkupParseContext *context, const gchar *text, gssize text_len, GError **error);
336 return g_markup_parse_context_parse(gMarkupParseContext
, Str
.toStringz(text
), textLen
, error
);