XML manipulation of landmarks

XML manipulation of landmarks — XML in-and output routines for landmark related data

Functions

void (*tag_start_callback) ()
void (*tag_ch_callback) ()
void (*tag_end_callback) ()
void xmlio_end_string ()
void xmlio_end_float ()
void xmlio_get_string ()
gboolean xml_write_float ()
int xml_sax_parse ()

Types and Values

Object Hierarchy


Description

The functions provided in tis section are used to load ans store landmarks and related information from and to XML trees.

Functions

tag_start_callback ()

void
(*tag_start_callback) (ParserState *user_data,
                       const xmlChar **attrs);

This is the prototype of the callback funtion that will be called by the SAX parser at the opening of a new XML tag.

Parameters

user_data

data passd in by the user when calling the SAX parser

 

attrs

attributes of the XML tag that was just opened.

 

tag_ch_callback ()

void
(*tag_ch_callback) (ParserState *user_data,
                    const xmlChar *ch,
                    int len);

This is the prototype of the callback funtion that will be called whenever a chunk of characters is read when handling an XML tag. The contents of a XML tag may come in parts, hence the incoming data should be accumulated.

Parameters

user_data

data passd in by the user when calling the SAX parser

 

ch

character string

 

len

length of the incomming character string

 

tag_end_callback ()

void
(*tag_end_callback) (ParserState *user_data,
                     const gchar *property);

This is the prototype of the callback funtion that will be called by the SAX parser at the closing of a XML tag.

Parameters

user_data

data passd in by the user when calling the SAX parser

 

property

property identifies this tag corresponds to.

 

xmlio_end_string ()

void
xmlio_end_string (ParserState *state,
                  const gchar *property);

Store the read string as property in the currently active entity

Parameters

state

holds the current state of the parser

 

property

the property that is currently read from the XML input

 

xmlio_end_float ()

void
xmlio_end_float (ParserState *state,
                 const gchar *property);

Store the read floating point value as property in the currently active entity

Parameters

state

holds the current state of the parser

 

property

the property that is currently read from the XML input

 

xmlio_get_string ()

void
xmlio_get_string (ParserState *state,
                  const xmlChar *ch,
                  int len);

Append the string ch to the currently read string in the parser state

Parameters

state

current XML parser state

 

ch

character string

 

len

length of the input character string

 

xml_write_float ()

gboolean
xml_write_float (xmlNodePtr root,
                 xmlNsPtr ns,
                 const gchar *tag,
                 gfloat f);

Store the value f as new node of root with tag tag in namespace ns

Parameters

root

root node to add thenew data to

 

ns

XML name space identified

 

tag

node tag to be used to store the data

 

f

floating point value to be stored

 

Returns

TRUE if successful, FALSE otherwise.


xml_sax_parse ()

int
xml_sax_parse (const gchar *filename,
               const ParserTags *tags,
               gpointer pdata);

Parse the given XML file by using the given callback table to handle the tags accordingly by calling xmlSAXUserParseFile from the libxml2 library.

Parameters

filename

filename of the input XML file

 

tags

A table of tags with their corresponding callback map

 

pdata

Private data passed to the parser state.

[closure]

Returns

0 in the case of success and the error number returned by xmlSAXUserParseFile

Types and Values

struct ParserTags

struct ParserTags {
	const gchar *tag_name;
	tag_start_callback start_callback;
	tag_ch_callback ch_callback;
	tag_end_callback end_callback;
	const ParserTags *parser_tags;
};

This table entry describes the handling of a certain XML tag. When the tag opens, it will call the start_callback function and push its related the property and ch_callback and end_callback values on the ParserStateStack that is used to parse the XML file at hand. If a new tag is read, that the sub-table will be used to identify the proper handler, and if none is available, the unknown tag handler will be used to skip over this tag.

Members

const gchar *tag_name;

name of the XML tag to be handled by this table entry

 

tag_start_callback start_callback;

callback to execute when the tag starts

 

tag_ch_callback ch_callback;

callback to execute when string data is read

 

tag_end_callback end_callback;

callback to execute when the tag ends, should handle storing of the read data

 

const ParserTags *parser_tags;

sub-table that describes the supported child-tags of this XML tag

 

END_PARSER_TAGS

#define END_PARSER_TAGS {0,0,0,0,0}

Defines the end of a parset tags table.


struct ParserState

struct ParserState {
	ParserStateStack *pss;
	gpointer data;
};

This structure holds the current state when parsing an XML file.

Members

ParserStateStack *pss;

stack to store the parser states

 

gpointer data;

additional user data that is passed to the parser

 

struct ParserStateStack

struct ParserStateStack {
	gint tag_id;
	gint unknown_depth;
	GString *property;
	tag_ch_callback ch_callback;
	tag_end_callback end_callback;
	gint n_parser_tags;
	const ParserTags *parser_tags;
	GString *ch;
	gpointer data;
};

A structure to hold the state of the parser.

Members

gint tag_id;

unused field??

 

gint unknown_depth;

xml-tree depth when reading (and discarding an unkown tag)

 

GString *property;

the property related to the tag that is currently read

 

tag_ch_callback ch_callback;

currently active callback function to handle read characters

 

tag_end_callback end_callback;

currently active callback funtion to call when the currently read tag ends

 

gint n_parser_tags;

size of following tag-callback map

 

const ParserTags *parser_tags;

table of tag-callback mappings

 

GString *ch;

string to accumulate corrently parsed section

 

gpointer data;

private data passed to the parser