The Gnome Chemistry Utils: xml-utils.h File Reference

- Main Page
- Namespaces
- Classes
- Files
- Directories

# xml-utils.h File Reference

`#include <libxml/parser.h>`
`#include "chemistry.h"`

Go to the source code of this file.

## Functions
xmlNodePtr | FindNodeByNameAndId (xmlNodePtr node, const char *name, const char *id=NULL)
bool | ReadPosition (xmlNodePtr node, const char *id, double *x, double *y, double *z=NULL)
bool | WritePosition (xmlDocPtr xml, xmlNodePtr node, const char *id, double x, double y, double z=0.0)
bool | ReadColor (xmlNodePtr node, const char *id, float *red, float *green, float *blue, float *alpha=NULL)
bool | WriteColor (xmlDocPtr xml, xmlNodePtr node, const char *id, double red, double green, double blue, double alpha=1.0)
bool | ReadRadius (xmlNodePtr node, GcuAtomicRadius &radius)
bool | WriteRadius (xmlDocPtr xml, xmlNodePtr node, const GcuAtomicRadius &radius)
char const * | GetStaticScale (char *buf)

## Detailed Description

Some helper functions to load / save Object instances.

Definition in file xml-utils.h.

## Function Documentation

xmlNodePtr FindNodeByNameAndId | ( | xmlNodePtr | node,
|  | const char * | name,
|  | const char * | id = `NULL` |
| ) |  |  |

ReadPosition

Parameters:

  | node,: | a pointer to the current parsed XML Node.
  | name,: | the name of the searched node.
  | id,: | the id property of the node or NULL if not significant. This parameter might be omitted in the last case.

Helper method used to search the xmlNode instance of name Name and with id property equal to id in the children of node. When id is NULL, the searched node does not have an id property. When id is not NULL, the searched node should be unique.

Returns:
  the matching node or NULL.

char const* GetStaticScale | ( | char * | buf | ) |

Parameters:

  | buf,: | a string to convert to a static instance.

This function is used to replace a dynamically allocated string by a static instance. It works managing a set of string instances. It is used for scale names (as for radii and electronegativity), hence its name.

Returns:
  a static version of buf or NULL if a new static string could not be created.

bool ReadColor | ( | xmlNodePtr | node,
|  | const char * | id,
|  | float * | red,
|  | float * | green,
|  | float * | blue,
|  | float * | alpha = `NULL` |
| ) |  |  |

Parameters:

  | node,: | a pointer to the xmlNode representing an Object instance.
  | id,: | the value of the id property of the color. This is used for Object instances having at least two colors.
  | red,: | a pointer to the red component of the color.
  | green,: | a pointer to the green component of the color.
  | blue,: | a pointer to the blue component of the color.
  | alpha,: | a pointer to the alpha component of the color or NULL if tranparency is not managed.

This method can be used to load a color in an Object instance. It should be used in cunjunction with WriteColor() which executes the inverse operation. If id is NULL, a color with no id property will be search and parsed.

Returns:
  true on success and false on failure.

bool ReadPosition | ( | xmlNodePtr | node,
|  | const char * | id,
|  | double * | x,
|  | double * | y,
|  | double * | z = `NULL` |
| ) |  |  |

Parameters:

  | node,: | a pointer to the xmlNode representing an Object instance.
  | id,: | the value of the id property of the position. This is used for example for arrows because both the head and the tail of the arrow are positions.
  | x,: | a pointer to the x coordinate of the position.
  | y,: | a pointer to the y coordinate of the position.
  | z,: | a pointer to the z coordinate of the position or NULL for 2D objects.

This method can be used to load the coordinates of a point in an Object instance. It should be used in cunjunction with WritePosition() which executes the inverse operation. If id is NULL, a position with no id property will be search and parsed.

Returns:
  true on success and false on failure.

bool ReadRadius | ( | xmlNodePtr | node,
|  | GcuAtomicRadius & | radius |
| ) |  |  |

Parameters:

  | node,: | a pointer to the xmlNode representing an Object instance.
  | radius,: | a GcuAtomicRadius structure.

This function parses the XML node representing a radius (written using WriteRadius()) and fills the fields in the GcuAtomicRadius structure with the data parsed.

Returns:
  true on success and false on failure.

bool WriteColor | ( | xmlDocPtr | xml,
|  | xmlNodePtr | node,
|  | const char * | id,
|  | double | red,
|  | double | green,
|  | double | blue,
|  | double | alpha = `1.0` |
| ) |  |  |

Parameters:

  | xml,: | a pointer to the xmlDoc used to serialize the document.
  | node,: | a pointer to the xmlNode representing an Object instance.
  | id,: | the value of the id property of the color. This is used for Object instances having at least two colors. of the arrow are positions.
  | red,: | the red component of the color.
  | green,: | the green component of the color.
  | blue,: | the blue component of the color.
  | alpha,: | the alpha component of the color.

Save a color as an XML node added to the children of node. This color can then be parsed using ReadColor().

Returns:
  true on success and false on failure.

bool WritePosition | ( | xmlDocPtr | xml,
|  | xmlNodePtr | node,
|  | const char * | id,
|  | double | x,
|  | double | y,
|  | double | z = `0.0` |
| ) |  |  |

WritePosition

Parameters:

  | xml,: | a pointer to the xmlDoc used to serialize the document.
  | node,: | a pointer to the xmlNode representing an Object instance.
  | id,: | the value of the id property of the position. This is used for example for arrows because both the head and the tail of the arrow are positions.
  | x,: | the x coordinate of the position.
  | y,: | the y coordinate of the position.
  | z,: | the z coordinate of the position.

Save a position as an XML node added to the children of node. This position can then be parsed using ReadPosition().

Returns:
  true on success and false on failure.

bool WriteRadius | ( | xmlDocPtr | xml,
|  | xmlNodePtr | node,
|  | const GcuAtomicRadius & | radius |
| ) |  |  |

Parameters:

  | xml,: | a pointer to the xmlDoc used to serialize the document.
  | node,: | a pointer to the xmlNode representing an Object instance.
  | radius,: | a GcuAtomicRadius structure.

Save a radius as an XML node added to the children of node. This radius can then be parsed using ReadRadius().

Returns:
  true on success and false on failure.