Menu

Data structures

Matthieu Labas

You will find most of the inline documentation in comments in header files.
Comments in C files are mostly to explain how the code is working, not how it should be used.

An XML document is a list of XML nodes, described by the XMLNode struct.
XML document

An XML document is considered as:

  • a file name
  • a list of nodes.
  • the root node

The root node is given by its index in the nodes array.
It usually happens that the root index is > 0, typically when XML prolog and comments are given before.

XML node

An XML node is basically what lies between the '<' and '>' characters. It is composed of:

  1. tag name that lies right after the <
  2. attributes between the tag name and the >:
    1. attribute name
    2. = sign
    3. attribute value
  3. potentially a tag "finisher" / before the >

<tag attribName="attribValue" ...>

Therefore, the XMLNode struct has pointers to all of these information, all of them being transparently allocated by sxmlc.

The tag_type attribute is an internal representation of the type, for the program to know how to handle the tag attribute.
Many nodes (e.g. prolog or comments) use the tag attribute to store its content. Hence, knowing the tag type eases its display:

  • TAG_FATHER (<mytag>) is a node that will have children. Nodes read after it will be added as children of this tag.
  • TAG_SELF (<mytag/>) is a "self-contained" node that has no children. Nodes read after it are siblings of this tag.
  • TAG_END (</mytag>) is an ending node that closes its father (if tag names matches). Nodes read after it are siblings of father tag. There is no XMLNode associated with this as it is only used internally by the parser.
  • TAG_INSTR (<?text?>) is a node used for prolog and processing instructions.
  • TAG_COMMENT (<!--text-->) is a comment node.
  • TAG_CDATA (<![CDATA[text]]/>) is a CDATA escaped node.
  • TAG_DOCTYPE (<!DOCTYPE text]/>) is a DOCTYPE node.

The user attribute is where you can put any type of data related to the node (e.g. pointer to a struct, ...).