1.17 <GMarkupParseContext>

Structure: <GMarkupParseContext>

A parse context is used to parse a stream of bytes that you expect to contain marked-up text.

See g_markup_parse_context_new(), GMarkupParser, and so on for more details.

Procedures

Method: markup-parse-context:end-parse? self ⇒ %return
Method: end-parse? self ⇒ %return

Signals to the <GMarkupParseContext> that all data has been fed into the parse context with markup-parse-context:parse?.

This function reports an error if the document isn’t complete, for example if elements are still open.

self

Passed: a <GMarkupParseContext>.

a <GMarkupParseContext>

%return

Returned: a boolean.

#t on success, #f if an error was set

Method: markup-parse-context:free self
Method: free self

Frees a <GMarkupParseContext>.

This function can’t be called from inside one of the GMarkupParser functions or while a subparser is pushed.

self

Passed: a <GMarkupParseContext>.

a <GMarkupParseContext>

Method: markup-parse-context:get-element self ⇒ %return
Method: get-element self ⇒ %return

Retrieves the name of the currently open element.

If called from the start_element or end_element handlers this will give the element_name as passed to those functions. For the parent elements, see markup-parse-context:get-element-stack.

self

Passed: a <GMarkupParseContext>.

a <GMarkupParseContext>

%return

Returned: a string.

the name of the currently open element, or #f

Method: markup-parse-context:get-element-stack self ⇒ %return
Method: get-element-stack self ⇒ %return

Retrieves the element stack from the internal state of the parser.

The returned GSList is a list of strings where the first item is the currently open tag (as would be returned by markup-parse-context:get-element) and the next item is its immediate parent.

This function is intended to be used in the start_element and end_element handlers where markup-parse-context:get-element would merely return the name of the element that is being processed.

self

Passed: a <GMarkupParseContext>.

a <GMarkupParseContext>

%return

Returned: a list, each a string.

the element stack, which must not be modified

Method: markup-parse-context:get-offset self ⇒ %return
Method: get-offset self ⇒ %return

Retrieves the current offset from the beginning of the document, in bytes.

The information is meant to accompany the values returned by markup-parse-context:get-position, and comes with the same accuracy guarantees.

self

Passed: a <GMarkupParseContext>.

a <GMarkupParseContext>

%return

Returned: an unsigned 64-bit integer.

the offset

Method: markup-parse-context:get-position self ⇒ line-number char-number
Method: get-position self ⇒ line-number char-number

Retrieves the current line number and the number of the character on that line. Intended for use in error messages; there are no strict semantics for what constitutes the "current" line number other than "the best number we could come up with for error messages."

self

Passed: a <GMarkupParseContext>.

a <GMarkupParseContext>

line-number

Returned: a 32-bit integer.

return location for a line number, or #f

char-number

Returned: a 32-bit integer.

return location for a char-on-line number, or #f

Method: markup-parse-context:get-tag-start self ⇒ line-number char-number offset
Method: get-tag-start self ⇒ line-number char-number offset

Retrieves the start position of the current start or end tag.

This function can be used in the start_element or end_element callbacks to obtain location information for error reporting.

Note that line-number and char-number are intended for human readable error messages and are therefore 1-based and in Unicode characters. offset on the other hand is meant for programmatic use, and thus is 0-based and in bytes.

The information is meant to accompany the values returned by markup-parse-context:get-position, and comes with the same accuracy guarantees.

self

Passed: a <GMarkupParseContext>.

a <GMarkupParseContext>

line-number

Returned: an unsigned 64-bit integer.

return location for the line number

char-number

Returned: an unsigned 64-bit integer.

return location for the character number

offset

Returned: an unsigned 64-bit integer.

return location for offset from the beginning of the document

Method: markup-parse-context:get-user-data self ⇒ %return
Method: get-user-data self ⇒ %return

Returns the user_data associated with self.

This will either be the user_data that was provided to g_markup_parse_context_new() or to the most recent call of g_markup_parse_context_push().

self

Passed: a <GMarkupParseContext>.

a <GMarkupParseContext>

%return

Returned: a foreign pointer, or #f.

the provided user_data. The returned data belongs to the markup context and will be freed when markup-parse-context:free is called.

Method: markup-parse-context:parse? self text text-len ⇒ %return
Method: parse? self text text-len ⇒ %return

Feed some data to the <GMarkupParseContext>.

The data need not be valid UTF-8; an error will be signaled if it’s invalid. The data need not be an entire document; you can feed a document into the parser incrementally, via multiple calls to this function. Typically, as you receive data from a network connection or file, you feed each received chunk of data into this function, aborting the process if an error occurs. Once an error is reported, no further data may be fed to the <GMarkupParseContext>; all errors are fatal.

self

Passed: a <GMarkupParseContext>.

a <GMarkupParseContext>

text

Passed: a string.

chunk of text to parse

text-len

Passed: a 64-bit integer.

length of text in bytes

%return

Returned: a boolean.

#f if an error occurred, #t on success

Method: markup-parse-context:pop self ⇒ %return
Method: pop self ⇒ %return

Completes the process of a temporary sub-parser redirection.

This function exists to collect the user_data allocated by a matching call to g_markup_parse_context_push(). It must be called in the end_element handler corresponding to the start_element handler during which g_markup_parse_context_push() was called. You must not call this function from the error callback – the user-data is provided directly to the callback in that case.

This function is not intended to be directly called by users interested in invoking subparsers. Instead, it is intended to be used by the subparsers themselves to implement a higher-level interface.

self

Passed: a <GMarkupParseContext>.

a <GMarkupParseContext>

%return

Returned: a foreign pointer, or #f.

the user data passed to g_markup_parse_context_push()

Method: markup-parse-context:ref self ⇒ %return
Method: ref self ⇒ %return

Increases the reference count of self.

self

Passed: a <GMarkupParseContext>.

a <GMarkupParseContext>

%return

Returned: a <GMarkupParseContext>.

the same self

Method: markup-parse-context:unref self
Method: unref self

Decreases the reference count of self. When its reference count drops to 0, it is freed.

self

Passed: a <GMarkupParseContext>.

a <GMarkupParseContext>