2 * "$Id: mxml-get.c 451 2014-01-04 21:50:06Z msweet $"
4 * Node get functions for Mini-XML, a small XML-like file parsing library.
6 * Copyright 2014 by Michael R Sweet.
8 * These coded instructions, statements, and computer programs are the
9 * property of Michael R Sweet and are protected by Federal copyright
10 * law. Distribution and use rights are outlined in the file "COPYING"
11 * which should have been included with this file. If this file is
12 * missing or damaged, see the license at:
14 * http://www.msweet.org/projects.php/Mini-XML
18 * Include necessary headers...
26 * 'mxmlGetCDATA()' - Get the value for a CDATA node.
28 * @code NULL@ is returned if the node is not a CDATA element.
30 * @since Mini-XML 2.7@
33 const char * /* O - CDATA value or NULL */
34 mxmlGetCDATA(mxml_node_t *node) /* I - Node to get */
37 * Range check input...
40 if (!node || node->type != MXML_ELEMENT ||
41 strncmp(node->value.element.name, "![CDATA[", 8))
45 * Return the text following the CDATA declaration...
48 return (node->value.element.name + 8);
53 * 'mxmlGetCustom()' - Get the value for a custom node.
55 * @code NULL@ is returned if the node (or its first child) is not a custom
58 * @since Mini-XML 2.7@
61 const void * /* O - Custom value or NULL */
62 mxmlGetCustom(mxml_node_t *node) /* I - Node to get */
65 * Range check input...
72 * Return the integer value...
75 if (node->type == MXML_CUSTOM)
76 return (node->value.custom.data);
77 else if (node->type == MXML_ELEMENT &&
79 node->child->type == MXML_CUSTOM)
80 return (node->child->value.custom.data);
87 * 'mxmlGetElement()' - Get the name for an element node.
89 * @code NULL@ is returned if the node is not an element node.
91 * @since Mini-XML 2.7@
94 const char * /* O - Element name or NULL */
95 mxmlGetElement(mxml_node_t *node) /* I - Node to get */
98 * Range check input...
101 if (!node || node->type != MXML_ELEMENT)
105 * Return the element name...
108 return (node->value.element.name);
113 * 'mxmlGetFirstChild()' - Get the first child of an element node.
115 * @code NULL@ is returned if the node is not an element node or if the node
118 * @since Mini-XML 2.7@
121 mxml_node_t * /* O - First child or NULL */
122 mxmlGetFirstChild(mxml_node_t *node) /* I - Node to get */
125 * Range check input...
128 if (!node || node->type != MXML_ELEMENT)
132 * Return the first child node...
135 return (node->child);
140 * 'mxmlGetInteger()' - Get the integer value from the specified node or its
143 * 0 is returned if the node (or its first child) is not an integer value node.
145 * @since Mini-XML 2.7@
148 int /* O - Integer value or 0 */
149 mxmlGetInteger(mxml_node_t *node) /* I - Node to get */
152 * Range check input...
159 * Return the integer value...
162 if (node->type == MXML_INTEGER)
163 return (node->value.integer);
164 else if (node->type == MXML_ELEMENT &&
166 node->child->type == MXML_INTEGER)
167 return (node->child->value.integer);
174 * 'mxmlGetLastChild()' - Get the last child of an element node.
176 * @code NULL@ is returned if the node is not an element node or if the node
179 * @since Mini-XML 2.7@
182 mxml_node_t * /* O - Last child or NULL */
183 mxmlGetLastChild(mxml_node_t *node) /* I - Node to get */
186 * Range check input...
189 if (!node || node->type != MXML_ELEMENT)
193 * Return the node type...
196 return (node->last_child);
201 * 'mxmlGetNextSibling()' - Get the next node for the current parent.
203 * @code NULL@ is returned if this is the last child for the current parent.
205 * @since Mini-XML 2.7@
209 mxmlGetNextSibling(mxml_node_t *node) /* I - Node to get */
212 * Range check input...
219 * Return the node type...
227 * 'mxmlGetOpaque()' - Get an opaque string value for a node or its first child.
229 * @code NULL@ is returned if the node (or its first child) is not an opaque
232 * @since Mini-XML 2.7@
235 const char * /* O - Opaque string or NULL */
236 mxmlGetOpaque(mxml_node_t *node) /* I - Node to get */
239 * Range check input...
246 * Return the integer value...
249 if (node->type == MXML_OPAQUE)
250 return (node->value.opaque);
251 else if (node->type == MXML_ELEMENT &&
253 node->child->type == MXML_OPAQUE)
254 return (node->child->value.opaque);
261 * 'mxmlGetParent()' - Get the parent node.
263 * @code NULL@ is returned for a root node.
265 * @since Mini-XML 2.7@
268 mxml_node_t * /* O - Parent node or NULL */
269 mxmlGetParent(mxml_node_t *node) /* I - Node to get */
272 * Range check input...
279 * Return the node type...
282 return (node->parent);
287 * 'mxmlGetPrevSibling()' - Get the previous node for the current parent.
289 * @code NULL@ is returned if this is the first child for the current parent.
291 * @since Mini-XML 2.7@
294 mxml_node_t * /* O - Previous node or NULL */
295 mxmlGetPrevSibling(mxml_node_t *node) /* I - Node to get */
298 * Range check input...
305 * Return the node type...
313 * 'mxmlGetReal()' - Get the real value for a node or its first child.
315 * 0.0 is returned if the node (or its first child) is not a real value node.
317 * @since Mini-XML 2.7@
320 double /* O - Real value or 0.0 */
321 mxmlGetReal(mxml_node_t *node) /* I - Node to get */
324 * Range check input...
331 * Return the integer value...
334 if (node->type == MXML_REAL)
335 return (node->value.real);
336 else if (node->type == MXML_ELEMENT &&
338 node->child->type == MXML_REAL)
339 return (node->child->value.real);
346 * 'mxmlGetText()' - Get the text value for a node or its first child.
348 * @code NULL@ is returned if the node (or its first child) is not a text node.
349 * The "whitespace" argument can be NULL.
351 * @since Mini-XML 2.7@
354 const char * /* O - Text string or NULL */
355 mxmlGetText(mxml_node_t *node, /* I - Node to get */
356 int *whitespace) /* O - 1 if string is preceded by whitespace, 0 otherwise */
359 * Range check input...
371 * Return the integer value...
374 if (node->type == MXML_TEXT)
377 *whitespace = node->value.text.whitespace;
379 return (node->value.text.string);
381 else if (node->type == MXML_ELEMENT &&
383 node->child->type == MXML_TEXT)
386 *whitespace = node->child->value.text.whitespace;
388 return (node->child->value.text.string);
401 * 'mxmlGetType()' - Get the node type.
403 * @code MXML_IGNORE@ is returned if "node" is @code NULL@.
405 * @since Mini-XML 2.7@
408 mxml_type_t /* O - Type of node */
409 mxmlGetType(mxml_node_t *node) /* I - Node to get */
412 * Range check input...
416 return (MXML_IGNORE);
419 * Return the node type...
427 * 'mxmlGetUserData()' - Get the user data pointer for a node.
429 * @since Mini-XML 2.7@
432 void * /* O - User data pointer */
433 mxmlGetUserData(mxml_node_t *node) /* I - Node to get */
436 * Range check input...
443 * Return the user data pointer...
446 return (node->user_data);
451 * End of "$Id: mxml-get.c 451 2014-01-04 21:50:06Z msweet $".