Skip to content

Midas C++ API - mxml (XML documents)

This page contains the full API reference for mxml (mxml/mxml.h), the library that midas uses for XML documents.

A document is held as a tree of MXML_NODE structures:

  • mxml_parse_file() and mxml_parse_buffer() read one
  • mxml_find_node() and mxml_get_xxx() look up its contents
  • mxml_write_tree() writes it out

The mxml_open_file() family writes an XML file element by element, without building a tree first.

The ODB can be saved in XML format. See ODB: programming.

mxml/mxml.h

Classes

mxml_struct

Defined in mxml/mxml.h:65

Attributes
attribute_name
char *attribute_name

Defined in mxml/mxml.h:70

attribute_value
char **attribute_value

Defined in mxml/mxml.h:71

child
PMXML_NODE child

Defined in mxml/mxml.h:76

line_number_end
int line_number_end

last line number in XML file, starting from 1

Defined in mxml/mxml.h:73

line_number_start
int line_number_start

first line number in XML file, starting from 1

Defined in mxml/mxml.h:72

n_attributes
int n_attributes

list of attributes

Defined in mxml/mxml.h:69

n_children
int n_children

list of children

Defined in mxml/mxml.h:75

name
char name[MXML_NAME_LENGTH]

name of element <[name]>[value]</[name]>

Defined in mxml/mxml.h:66

node_type
int node_type

type of node XXX_NODE

Defined in mxml/mxml.h:67

parent
PMXML_NODE parent

pointer to parent element

Defined in mxml/mxml.h:74

value
char *value

value of element

Defined in mxml/mxml.h:68

MXML_WRITER

Defined in mxml/mxml.h:51

Attributes
buffer
char *buffer

Defined in mxml/mxml.h:53

buffer_len
int buffer_len

Defined in mxml/mxml.h:55

buffer_size
int buffer_size

Defined in mxml/mxml.h:54

data_was_written
int data_was_written

Defined in mxml/mxml.h:58

element_is_open
int element_is_open

Defined in mxml/mxml.h:57

fh
int fh

Defined in mxml/mxml.h:52

level
int level

Defined in mxml/mxml.h:56

stack
char **stack

Defined in mxml/mxml.h:59

translate
int translate

Defined in mxml/mxml.h:60

Type definitions

MXML_NODE

typedef struct mxml_struct MXML_NODE

Defined in mxml/mxml.h:65

PMXML_NODE

typedef struct mxml_struct *PMXML_NODE

Defined in mxml/mxml.h:63

Functions

mxml_add_attribute

int mxml_add_attribute(PMXML_NODE pnode, const char *attrib_name, const char *attrib_value)

add an attribute to an existing node

Declared in mxml/mxml.h:116, defined in mxml/mxml.cxx:869

mxml_add_node

PMXML_NODE mxml_add_node(PMXML_NODE parent, const char *node_name, const char *value)

write value of an XML element, like <[name]>[value]</[name]>

Declared in mxml/mxml.h:119, defined in mxml/mxml.cxx:782

mxml_add_node_at

PMXML_NODE mxml_add_node_at(PMXML_NODE parent, const char *node_name, const char *value, int idx)

add a subnode (child) to an existing parent node at the end

Declared in mxml/mxml.h:120, defined in mxml/mxml.cxx:792

mxml_add_special_node

PMXML_NODE mxml_add_special_node(PMXML_NODE parent, int node_type, const char *node_name, const char *value)

add a subnode (child) to an existing parent node at the end

Declared in mxml/mxml.h:117, defined in mxml/mxml.cxx:772

mxml_add_special_node_at

PMXML_NODE mxml_add_special_node_at(PMXML_NODE parent, int node_type, const char *node_name, const char *value, int idx)

add a subnode (child) to an existing parent node as a specific position

Declared in mxml/mxml.h:118, defined in mxml/mxml.cxx:724

mxml_add_tree

int mxml_add_tree(PMXML_NODE parent, PMXML_NODE tree)

add a whole node tree to an existing parent node at the end

Declared in mxml/mxml.h:123, defined in mxml/mxml.cxx:859

mxml_add_tree_at

int mxml_add_tree_at(PMXML_NODE parent, PMXML_NODE tree, int idx)

add a whole node tree to an existing parent node at a specific position

Declared in mxml/mxml.h:124, defined in mxml/mxml.cxx:802

mxml_basename

void mxml_basename(char *path)

mxml_basename deletes any prefix ending with the last slash '/' character present in path. mxml_dirname deletes the filename portion, beginning with the last slash '/' character to the end of path. Followings are examples from these functions

path dirname basename "/" "/" "" "." "." "." "" "" "" "/test.txt" "/" "test.txt" "path/to/test.txt" "path/to" "test.txt" "test.txt "." "test.txt"

Under Windows, '\' and ':' are recognized ad separator too.

Declared in mxml/mxml.h:145, defined in mxml/mxml.cxx:2408

mxml_clone_tree

PMXML_NODE mxml_clone_tree(PMXML_NODE tree)

Declared in mxml/mxml.h:122, defined in mxml/mxml.cxx:2256

mxml_close_buffer

char *mxml_close_buffer(MXML_WRITER *writer)

close a file opened with mxml_open_writer

Declared in mxml/mxml.h:101, defined in mxml/mxml.cxx:659

mxml_close_file

int mxml_close_file(MXML_WRITER *writer)

close a file opened with mxml_open_writer

Declared in mxml/mxml.h:102, defined in mxml/mxml.cxx:684

mxml_create_root_node

PMXML_NODE mxml_create_root_node()

create root node of an XML tree

Declared in mxml/mxml.h:135, defined in mxml/mxml.cxx:708

mxml_debug_tree

void mxml_debug_tree(PMXML_NODE tree, int level)

print XML tree for debugging

Declared in mxml/mxml.h:140, defined in mxml/mxml.cxx:2287

mxml_delete_attribute

int mxml_delete_attribute(PMXML_NODE pnode, const char *attrib_name)

Declared in mxml/mxml.h:133, defined in mxml/mxml.cxx:1306

mxml_delete_node

int mxml_delete_node(PMXML_NODE pnode)

free memory of a node and remove it from the parent's child list

Declared in mxml/mxml.h:132, defined in mxml/mxml.cxx:1273

mxml_dirname

void mxml_dirname(char* path)

Declared in mxml/mxml.h:144, defined in mxml/mxml.cxx:2435

mxml_end_element

int mxml_end_element(MXML_WRITER *writer)

close an open XML element

Declared in mxml/mxml.h:95, defined in mxml/mxml.cxx:487

mxml_find_node

PMXML_NODE mxml_find_node(PMXML_NODE tree, const char *xml_path)

Search for a specific XML node with a subset of XPATH specifications. Return first found node. For syntax see mxml_find_nodes()

Declared in mxml/mxml.h:107, defined in mxml/mxml.cxx:1106

mxml_find_nodes

int mxml_find_nodes(PMXML_NODE tree, const char *xml_path, PMXML_NODE **nodelist)

Declared in mxml/mxml.h:108, defined in mxml/mxml.cxx:1088

mxml_free_tree

void mxml_free_tree(PMXML_NODE tree)

free memory of XML tree, must be called after any mxml_create_root_node() or mxml_parse_file()

Declared in mxml/mxml.h:141, defined in mxml/mxml.cxx:2337

mxml_get_attribute

char *mxml_get_attribute(PMXML_NODE pnode, const char *name)

Declared in mxml/mxml.h:114, defined in mxml/mxml.cxx:1163

mxml_get_line_number_end

int mxml_get_line_number_end(PMXML_NODE pnode)

Declared in mxml/mxml.h:112, defined in mxml/mxml.cxx:1155

mxml_get_line_number_start

int mxml_get_line_number_start(PMXML_NODE pnode)

Declared in mxml/mxml.h:111, defined in mxml/mxml.cxx:1147

mxml_get_name

char *mxml_get_name(PMXML_NODE pnode)

Declared in mxml/mxml.h:109, defined in mxml/mxml.cxx:1131

mxml_get_node_at_line

PMXML_NODE mxml_get_node_at_line(PMXML_NODE tree, int linenumber)

Retieve node at a certain line number

Declared in mxml/mxml.h:113, defined in mxml/mxml.cxx:2470

mxml_get_number_of_children

int mxml_get_number_of_children(PMXML_NODE pnode)

return number of subnodes (children) of a node

Declared in mxml/mxml.h:104, defined in mxml/mxml.cxx:894

mxml_get_parent

PMXML_NODE mxml_get_parent(PMXML_NODE pnode)

Declared in mxml/mxml.h:105, defined in mxml/mxml.cxx:1123

mxml_get_value

char *mxml_get_value(PMXML_NODE pnode)

Declared in mxml/mxml.h:110, defined in mxml/mxml.cxx:1139

mxml_open_buffer

MXML_WRITER *mxml_open_buffer()

open a memory buffer and write XML header

Declared in mxml/mxml.h:91, defined in mxml/mxml.cxx:223

mxml_open_file

MXML_WRITER *mxml_open_file(const char *file_name)

open a file and write XML header

Declared in mxml/mxml.h:90, defined in mxml/mxml.cxx:271

mxml_parse_buffer

PMXML_NODE mxml_parse_buffer(const char *buffer, char *error, int error_size, int *error_line)

Parse a XML buffer and convert it into a tree of MXML_NODE's. Return NULL in case of an error, return error description. Optional file_name is used for error reporting if called from mxml_parse_file()

Declared in mxml/mxml.h:137, defined in mxml/mxml.cxx:1384

mxml_parse_entity

int mxml_parse_entity(char **buf, const char* file_name, char *error, int error_size, int *error_line)

parse !ENTYTY entries of XML files and replace with references. Return 0 in case of no errors, return error description. Optional file_name is used for error reporting if called from mxml_parse_file()

Declared in mxml/mxml.h:138, defined in mxml/mxml.cxx:1705

mxml_parse_file

PMXML_NODE mxml_parse_file(const char *file_name, char *error, int error_size, int *error_line)

parse a XML file and convert it into a tree of MXML_NODE's. Return NULL in case of an error, return error description

Declared in mxml/mxml.h:136, defined in mxml/mxml.cxx:2102

mxml_print_tree

int mxml_print_tree(char *buffer, int *buffer_size, PMXML_NODE tree)

write a complete XML tree to a buffer

Declared in mxml/mxml.h:139, defined in mxml/mxml.cxx:2224

mxml_replace_attribute_name

int mxml_replace_attribute_name(PMXML_NODE pnode, const char *old_name, const char *new_name)

change the name of an attribute, keep its value

Declared in mxml/mxml.h:129, defined in mxml/mxml.cxx:1231

mxml_replace_attribute_value

int mxml_replace_attribute_value(PMXML_NODE pnode, const char *attrib_name, const char *attrib_value)

change the value of an attribute

Declared in mxml/mxml.h:130, defined in mxml/mxml.cxx:1251

mxml_replace_node_name

int mxml_replace_node_name(PMXML_NODE pnode, const char *new_name)

Declared in mxml/mxml.h:126, defined in mxml/mxml.cxx:1177

mxml_replace_node_value

int mxml_replace_node_value(PMXML_NODE pnode, const char *value)

Declared in mxml/mxml.h:127, defined in mxml/mxml.cxx:1185

mxml_replace_subvalue

int mxml_replace_subvalue(PMXML_NODE pnode, const char *name, const char *value)

replace value os a subnode, like

<parent> <child>value</child> </parent>

if pnode=parent, and "name"="child", then "value" gets replaced

Declared in mxml/mxml.h:128, defined in mxml/mxml.cxx:1212

mxml_set_translate

int mxml_set_translate(MXML_WRITER *writer, int flag)

set translation of <,>,",',&, on/off in writer

Declared in mxml/mxml.h:92, defined in mxml/mxml.cxx:417

mxml_start_element

int mxml_start_element(MXML_WRITER *writer, const char *name)

Declared in mxml/mxml.h:93, defined in mxml/mxml.cxx:470

mxml_start_element_noindent

int mxml_start_element_noindent(MXML_WRITER *writer, const char *name)

Declared in mxml/mxml.h:94, defined in mxml/mxml.cxx:477

mxml_subnode

PMXML_NODE mxml_subnode(PMXML_NODE pnode, int idx)

return number of subnodes (children) of a node

Declared in mxml/mxml.h:106, defined in mxml/mxml.cxx:905

mxml_suppress_date

void mxml_suppress_date(int suppress)

suppress writing date at the top of file.

Declared in mxml/mxml.h:89, defined in mxml/mxml.cxx:261

mxml_write_attribute

int mxml_write_attribute(MXML_WRITER *writer, const char *name, const char *value)

write an attribute to the currently open XML element

Declared in mxml/mxml.h:98, defined in mxml/mxml.cxx:527

mxml_write_comment

int mxml_write_comment(MXML_WRITER *writer, const char *string)

write a comment to an XML file, enclosed in "<!--" and "-->"

Declared in mxml/mxml.h:96, defined in mxml/mxml.cxx:617

mxml_write_element

int mxml_write_element(MXML_WRITER *writer, const char *name, const char *value)

shortcut to write an element with a value but without attribute

Declared in mxml/mxml.h:97, defined in mxml/mxml.cxx:644

mxml_write_empty_line

int mxml_write_empty_line(MXML_WRITER *writer)

write empty line

Declared in mxml/mxml.h:100, defined in mxml/mxml.cxx:599

mxml_write_tree

int mxml_write_tree(const char *file_name, PMXML_NODE tree)

write a complete XML tree to a file

Declared in mxml/mxml.h:142, defined in mxml/mxml.cxx:2198

mxml_write_value

int mxml_write_value(MXML_WRITER *writer, const char *value)

write value of an XML element, like <[name]>[value]</[name]>

Declared in mxml/mxml.h:99, defined in mxml/mxml.cxx:571

Macros

COMMENT_NODE

#define COMMENT_NODE 4

Defined in mxml/mxml.h:36

DIR_SEPARATOR

#define DIR_SEPARATOR '/'

Defined in mxml/mxml.h:48

DOCUMENT_NODE

#define DOCUMENT_NODE 5

Defined in mxml/mxml.h:37

ELEMENT_NODE

#define ELEMENT_NODE 1

Defined in mxml/mxml.h:33

EXPRT

#define EXPRT

Defined in mxml/mxml.h:85

EXTERNAL_ENTITY

#define EXTERNAL_ENTITY 1

Defined in mxml/mxml.h:40

INTERNAL_ENTITY

#define INTERNAL_ENTITY 0

Defined in mxml/mxml.h:39

MXML_MAX_CONDITION

#define MXML_MAX_CONDITION 10

Defined in mxml/mxml.h:43

MXML_MAX_ENTITY

#define MXML_MAX_ENTITY 50

Defined in mxml/mxml.h:41

MXML_NAME_LENGTH

#define MXML_NAME_LENGTH 64

Defined in mxml/mxml.h:31

PROCESSING_INSTRUCTION_NODE

#define PROCESSING_INSTRUCTION_NODE 3

Defined in mxml/mxml.h:35

TEXT_NODE

#define TEXT_NODE 2

Defined in mxml/mxml.h:34