Skip to content

XMLNode_getPrefix unexpectedly returns NULL when prefix is absent #390

@eltix

Description

@eltix

Issue description

This is the documentation of the XMLNode_getPrefix() function. If the XML node has no prefix, e.g. as in this annotation node <COPASI xmlns="http://www.copasi.org/static/sbml">, the function allegedly returns the empty string.

/**
 * Returns the namespace prefix of this XML element.
 *
 * @param node XMLNode_t structure to be queried.
 *
 * @return the namespace prefix of this XML element.
 *
 * @note If no prefix
 * exists, an empty string will be return.
 *
 * @memberof XMLNode_t
 */
LIBLAX_EXTERN
const char *
XMLNode_getPrefix (const XMLNode_t *node);

However the implementation contradicts the documentation:

const char *
XMLNode_getPrefix (const XMLNode_t *node)
{
  if (node == NULL) return NULL;
  return node->getPrefix().empty() ? NULL : node->getPrefix().c_str();
}

Indeed, the function returns the null pointer instead. Therefore, either the documentation or the implementation should be amended. If the option of keeping the current implementation is preferred, then it would be nice to add a

bool XMLNode_hasPrefix(const XMLNode_t *node)

function (or could be called isSetPrefix) which would allow to check whether prefix is set and mention that function in the documentation like it is done for XMLNode_getAttrName for instance

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions