1mxml(3) Mini-XML API mxml(3)
2
3
4
6 mxml - Mini-XML API
7
9 #include <mxml.h>
10
12 -lmxml
13
15 Mini-XML is a small XML parsing library that you can use to read XML
16 and XML-like data files in your application without requiring large
17 non-standard libraries. Mini-XML only requires an ANSI C compatible
18 compiler (GCC works, as do most vendors' ANSI C compilers) and a "make"
19 program.
20
21 Mini-XML provides the following functionality:
22
23 · Reading of UTF-8 and UTF-16 and writing of UTF-8 encoded XML files
24 and strings.
25
26 · Data is stored in a linked-list tree structure, preserving the XML
27 data hierarchy.
28
29 · Supports arbitrary element names, attributes, and attribute values
30 with no preset limits, just available memory.
31
32 · Supports integer, real, opaque ("cdata"), and text data types in
33 "leaf" nodes.
34
35 · Functions for creating, indexing, and managing trees of data.
36
37 · "Find" and "walk" functions for easily locating and navigating
38 trees of data.
39
40 Mini-XML doesn't do validation or other types of processing on the data
41 based upon schema files or other sources of definition information, nor
42 does it support character entities other than those required by the XML
43 specification.
44
46 Mini-XML provides a single header file which you include:
47
48 #include <mxml.h>
49
50 Nodes are defined by the "mxml_node_t" structure; the "type" member
51 defines the node type (element, integer, opaque, real, or text) which
52 determines which value you want to look at in the "value" union. New
53 nodes can be created using the "mxmlNewElement()", "mxmlNewInteger()",
54 "mxmlNewOpaque()", "mxmlNewReal()", and "mxmlNewText()" functions.
55 Only elements can have child nodes, and the top node must be an ele‐
56 ment, usually "?xml".
57
58 You load an XML file using the "mxmlLoadFile()" function:
59
60 FILE *fp;
61 mxml_node_t *tree;
62
63 fp = fopen("filename.xml", "r");
64 tree = mxmlLoadFile(NULL, fp, MXML_NO_CALLBACK);
65 fclose(fp);
66
67 Similarly, you save an XML file using the "mxmlSaveFile()" function:
68
69 FILE *fp;
70 mxml_node_t *tree;
71
72 fp = fopen("filename.xml", "w");
73 mxmlSaveFile(tree, fp, MXML_NO_CALLBACK);
74 fclose(fp);
75
76 The "mxmlLoadString()", "mxmlSaveAllocString()", and "mxmlSaveString()"
77 functions load XML node trees from and save XML node trees to strings:
78
79 char buffer[8192];
80 char *ptr;
81 mxml_node_t *tree;
82
83 ...
84 tree = mxmlLoadString(NULL, buffer, MXML_NO_CALLBACK);
85
86 ...
87 mxmlSaveString(tree, buffer, sizeof(buffer),
88 MXML_NO_CALLBACK);
89
90 ...
91 ptr = mxmlSaveAllocString(tree, MXML_NO_CALLBACK);
92
93 You can find a named element/node using the "mxmlFindElement()" func‐
94 tion:
95
96 mxml_node_t *node = mxmlFindElement(tree, tree, "name",
97 "attr", "value",
98 MXML_DESCEND);
99
100 The "name", "attr", and "value" arguments can be passed as NULL to act
101 as wildcards, e.g.:
102
103 /* Find the first "a" element */
104 node = mxmlFindElement(tree, tree, "a", NULL, NULL,
105 MXML_DESCEND);
106
107 /* Find the first "a" element with "href" attribute */
108 node = mxmlFindElement(tree, tree, "a", "href", NULL,
109 MXML_DESCEND);
110
111 /* Find the first "a" element with "href" to a URL */
112 node = mxmlFindElement(tree, tree, "a", "href",
113 "http://www.easysw.com/~mike/mxml/",
114 MXML_DESCEND);
115
116 /* Find the first element with a "src" attribute*/
117 node = mxmlFindElement(tree, tree, NULL, "src", NULL,
118 MXML_DESCEND);
119
120 /* Find the first element with a "src" = "foo.jpg" */
121 node = mxmlFindElement(tree, tree, NULL, "src",
122 "foo.jpg", MXML_DESCEND);
123
124 You can also iterate with the same function:
125
126 mxml_node_t *node;
127
128 for (node = mxmlFindElement(tree, tree, "name", NULL,
129 NULL, MXML_DESCEND);
130 node != NULL;
131 node = mxmlFindElement(node, tree, "name", NULL,
132 NULL, MXML_DESCEND))
133 {
134 ... do something ...
135 }
136
137 Finally, once you are done with the XML data, use the "mxmlDelete()"
138 function to recursively free the memory that is used for a particular
139 node or the entire tree:
140
141 mxmlDelete(tree);
142
144 mxml_sax_event_e
145 SAX event type.
146
147 MXML_SAX_CDATA
148 CDATA node
149
150 MXML_SAX_COMMENT
151 Comment node
152
153 MXML_SAX_DATA
154 Data node
155
156 MXML_SAX_DIRECTIVE
157 Processing directive node
158
159 MXML_SAX_ELEMENT_CLOSE
160 Element closed
161
162 MXML_SAX_ELEMENT_OPEN
163 Element opened
164
165 mxml_type_e
166 The XML node type.
167
168 MXML_CUSTOM
169 Custom data
170
171 MXML_ELEMENT
172 XML element with attributes
173
174 MXML_IGNORE
175 Ignore/throw away node
176
177 MXML_INTEGER
178 Integer value
179
180 MXML_OPAQUE
181 Opaque string
182
183 MXML_REAL
184 Real value
185
186 MXML_TEXT
187 Text fragment
188
190 mxmlAdd
191 Add a node to a tree.
192
193 void mxmlAdd (
194 mxml_node_t *parent,
195 int where,
196 mxml_node_t *child,
197 mxml_node_t *node
198 );
199
200 Adds the specified node to the parent. If the child argument is not
201 NULL, puts the new node before or after the specified child depending
202 on the value of the where argument. If the child argument is NULL, puts
203 the new node at the beginning of the child list (MXML_ADD_BEFORE) or at
204 the end of the child list (MXML_ADD_AFTER). The constant
205 MXML_ADD_TO_PARENT can be used to specify a NULL child pointer.
206
207 mxmlDelete
208 Delete a node and all of its children.
209
210 void mxmlDelete (
211 mxml_node_t *node
212 );
213
214 If the specified node has a parent, this function first removes the
215 node from its parent using the mxmlRemove() function.
216
217 mxmlElementDeleteAttr
218 Delete an attribute.
219
220 void mxmlElementDeleteAttr (
221 mxml_node_t *node,
222 const char *name
223 );
224
225 mxmlElementGetAttr
226 Get an attribute.
227
228 const char * mxmlElementGetAttr (
229 mxml_node_t *node,
230 const char *name
231 );
232
233 This function returns NULL if the node is not an element or the named
234 attribute does not exist.
235
236 mxmlElementSetAttr
237 Set an attribute.
238
239 void mxmlElementSetAttr (
240 mxml_node_t *node,
241 const char *name,
242 const char *value
243 );
244
245 If the named attribute already exists, the value of the attribute is
246 replaced by the new string value. The string value is copied into the
247 element node. This function does nothing if the node is not an element.
248
249 mxmlElementSetAttrf
250 Set an attribute with a formatted value.
251
252 void mxmlElementSetAttrf (
253 mxml_node_t *node,
254 const char *name,
255 const char *format,
256 ...
257 );
258
259 If the named attribute already exists, the value of the attribute is
260 replaced by the new formatted string. The formatted string value is
261 copied into the element node. This function does nothing if the node is
262 not an element.
263
264
265
266 mxmlEntityAddCallback
267 Add a callback to convert entities to Unicode.
268
269 int mxmlEntityAddCallback (void);
270
271 mxmlEntityGetName
272 Get the name that corresponds to the character value.
273
274 const char * mxmlEntityGetName (
275 int val
276 );
277
278 If val does not need to be represented by a named entity, NULL is
279 returned.
280
281 mxmlEntityGetValue
282 Get the character corresponding to a named entity.
283
284 int mxmlEntityGetValue (
285 const char *name
286 );
287
288 The entity name can also be a numeric constant. -1 is returned if the
289 name is not known.
290
291 mxmlEntityRemoveCallback
292 Remove a callback.
293
294 void mxmlEntityRemoveCallback (void);
295
296 mxmlFindElement
297 Find the named element.
298
299 mxml_node_t * mxmlFindElement (
300 mxml_node_t *node,
301 mxml_node_t *top,
302 const char *name,
303 const char *attr,
304 const char *value,
305 int descend
306 );
307
308 The search is constrained by the name, attribute name, and value; any
309 NULL names or values are treated as wildcards, so different kinds of
310 searches can be implemented by looking for all elements of a given name
311 or all elements with a specific attribute. The descend argument deter‐
312 mines whether the search descends into child nodes; normally you will
313 use MXML_DESCEND_FIRST for the initial search and MXML_NO_DESCEND to
314 find additional direct descendents of the node. The top node argument
315 constrains the search to a particular node's children.
316
317 mxmlIndexDelete
318 Delete an index.
319
320 void mxmlIndexDelete (
321 mxml_index_t *ind
322 );
323
324 mxmlIndexEnum
325 Return the next node in the index.
326
327 mxml_node_t * mxmlIndexEnum (
328 mxml_index_t *ind
329 );
330
331 Nodes are returned in the sorted order of the index.
332
333 mxmlIndexFind
334 Find the next matching node.
335
336 mxml_node_t * mxmlIndexFind (
337 mxml_index_t *ind,
338 const char *element,
339 const char *value
340 );
341
342 You should call mxmlIndexReset() prior to using this function for the
343 first time with a particular set of "element" and "value" strings.
344 Passing NULL for both "element" and "value" is equivalent to calling
345 mxmlIndexEnum().
346
347 mxmlIndexNew
348 Create a new index.
349
350 mxml_index_t * mxmlIndexNew (
351 mxml_node_t *node,
352 const char *element,
353 const char *attr
354 );
355
356 The index will contain all nodes that contain the named element and/or
357 attribute. If both "element" and "attr" are NULL, then the index will
358 contain a sorted list of the elements in the node tree. Nodes are
359 sorted by element name and optionally by attribute value if the "attr"
360 argument is not NULL.
361
362 mxmlIndexReset
363 Reset the enumeration/find pointer in the index and return the first
364 node in the index.
365
366 mxml_node_t * mxmlIndexReset (
367 mxml_index_t *ind
368 );
369
370 This function should be called prior to using mxmlIndexEnum() or mxm‐
371 lIndexFind() for the first time.
372
373 mxmlLoadFd
374 Load a file descriptor into an XML node tree.
375
376 mxml_node_t * mxmlLoadFd (
377 mxml_node_t *top,
378 int fd,
379 mxml_load_cb_t cb
380 );
381
382 The nodes in the specified file are added to the specified top node.
383 If no top node is provided, the XML file MUST be well-formed with a
384 single parent node like <?xml> for the entire file. The callback func‐
385 tion returns the value type that should be used for child nodes. If
386 MXML_NO_CALLBACK is specified then all child nodes will be either
387 MXML_ELEMENT or MXML_TEXT nodes.
388
389 The constants MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK,
390 MXML_REAL_CALLBACK, and MXML_TEXT_CALLBACK are defined for loading
391 child nodes of the specified type.
392
393 mxmlLoadFile
394 Load a file into an XML node tree.
395
396 mxml_node_t * mxmlLoadFile (
397 mxml_node_t *top,
398 FILE *fp,
399 mxml_load_cb_t cb
400 );
401
402 The nodes in the specified file are added to the specified top node.
403 If no top node is provided, the XML file MUST be well-formed with a
404 single parent node like <?xml> for the entire file. The callback func‐
405 tion returns the value type that should be used for child nodes. If
406 MXML_NO_CALLBACK is specified then all child nodes will be either
407 MXML_ELEMENT or MXML_TEXT nodes.
408
409 The constants MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK,
410 MXML_REAL_CALLBACK, and MXML_TEXT_CALLBACK are defined for loading
411 child nodes of the specified type.
412
413 mxmlLoadString
414 Load a string into an XML node tree.
415
416 mxml_node_t * mxmlLoadString (
417 mxml_node_t *top,
418 const char *s,
419 mxml_load_cb_t cb
420 );
421
422 The nodes in the specified string are added to the specified top node.
423 If no top node is provided, the XML string MUST be well-formed with a
424 single parent node like <?xml> for the entire string. The callback
425 function returns the value type that should be used for child nodes.
426 If MXML_NO_CALLBACK is specified then all child nodes will be either
427 MXML_ELEMENT or MXML_TEXT nodes.
428
429 The constants MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK,
430 MXML_REAL_CALLBACK, and MXML_TEXT_CALLBACK are defined for loading
431 child nodes of the specified type.
432
433 mxmlNewCDATA
434 Create a new CDATA node.
435
436 mxml_node_t * mxmlNewCDATA (
437 mxml_node_t *parent,
438 const char *data
439 );
440
441 The new CDATA node is added to the end of the specified parent's child
442 list. The constant MXML_NO_PARENT can be used to specify that the new
443 CDATA node has no parent. The data string must be nul-terminated and is
444 copied into the new node. CDATA nodes use the MXML_ELEMENT type.
445
446
447
448 mxmlNewCustom
449 Create a new custom data node.
450
451 mxml_node_t * mxmlNewCustom (
452 mxml_node_t *parent,
453 void *data,
454 mxml_custom_destroy_cb_t destroy
455 );
456
457 The new custom node is added to the end of the specified parent's child
458 list. The constant MXML_NO_PARENT can be used to specify that the new
459 element node has no parent. NULL can be passed when the data in the
460 node is not dynamically allocated or is separately managed.
461
462
463
464 mxmlNewElement
465 Create a new element node.
466
467 mxml_node_t * mxmlNewElement (
468 mxml_node_t *parent,
469 const char *name
470 );
471
472 The new element node is added to the end of the specified parent's
473 child list. The constant MXML_NO_PARENT can be used to specify that the
474 new element node has no parent.
475
476 mxmlNewInteger
477 Create a new integer node.
478
479 mxml_node_t * mxmlNewInteger (
480 mxml_node_t *parent,
481 int integer
482 );
483
484 The new integer node is added to the end of the specified parent's
485 child list. The constant MXML_NO_PARENT can be used to specify that the
486 new integer node has no parent.
487
488 mxmlNewOpaque
489 Create a new opaque string.
490
491 mxml_node_t * mxmlNewOpaque (
492 mxml_node_t *parent,
493 const char *opaque
494 );
495
496 The new opaque node is added to the end of the specified parent's child
497 list. The constant MXML_NO_PARENT can be used to specify that the new
498 opaque node has no parent. The opaque string must be nul-terminated and
499 is copied into the new node.
500
501 mxmlNewReal
502 Create a new real number node.
503
504 mxml_node_t * mxmlNewReal (
505 mxml_node_t *parent,
506 double real
507 );
508
509 The new real number node is added to the end of the specified parent's
510 child list. The constant MXML_NO_PARENT can be used to specify that the
511 new real number node has no parent.
512
513 mxmlNewText
514 Create a new text fragment node.
515
516 mxml_node_t * mxmlNewText (
517 mxml_node_t *parent,
518 int whitespace,
519 const char *string
520 );
521
522 The new text node is added to the end of the specified parent's child
523 list. The constant MXML_NO_PARENT can be used to specify that the new
524 text node has no parent. The whitespace parameter is used to specify
525 whether leading whitespace is present before the node. The text string
526 must be nul-terminated and is copied into the new node.
527
528 mxmlNewTextf
529 Create a new formatted text fragment node.
530
531 mxml_node_t * mxmlNewTextf (
532 mxml_node_t *parent,
533 int whitespace,
534 const char *format,
535 ...
536 );
537
538 The new text node is added to the end of the specified parent's child
539 list. The constant MXML_NO_PARENT can be used to specify that the new
540 text node has no parent. The whitespace parameter is used to specify
541 whether leading whitespace is present before the node. The format
542 string must be nul-terminated and is formatted into the new node.
543
544 mxmlNewXML
545 Create a new XML document tree.
546
547 mxml_node_t * mxmlNewXML (
548 const char *version
549 );
550
551 The "version" argument specifies the version number to put in the ?xml
552 element node. If NULL, version 1.0 is assumed.
553
554
555
556 mxmlRelease
557 Release a node.
558
559 int mxmlRelease (
560 mxml_node_t *node
561 );
562
563 When the reference count reaches zero, the node (and any children) is
564 deleted via mxmlDelete().
565
566
567
568 mxmlRemove
569 Remove a node from its parent.
570
571 void mxmlRemove (
572 mxml_node_t *node
573 );
574
575 Does not free memory used by the node - use mxmlDelete() for that.
576 This function does nothing if the node has no parent.
577
578 mxmlRetain
579 Retain a node.
580
581 int mxmlRetain (
582 mxml_node_t *node
583 );
584
585 mxmlSAXLoadFd
586 Load a file descriptor into an XML node tree using a SAX callback.
587
588 mxml_node_t * mxmlSAXLoadFd (
589 mxml_node_t *top,
590 int fd,
591 mxml_load_cb_t cb,
592 mxml_sax_cb_t sax_cb,
593 void *sax_data
594 );
595
596 The nodes in the specified file are added to the specified top node.
597 If no top node is provided, the XML file MUST be well-formed with a
598 single parent node like <?xml> for the entire file. The callback func‐
599 tion returns the value type that should be used for child nodes. If
600 MXML_NO_CALLBACK is specified then all child nodes will be either
601 MXML_ELEMENT or MXML_TEXT nodes.
602
603 The constants MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK,
604 MXML_REAL_CALLBACK, and MXML_TEXT_CALLBACK are defined for loading
605 child nodes of the specified type.
606
607 The SAX callback must call mxmlRetain() for any nodes that need to be
608 kept for later use. Otherwise, nodes are deleted when the parent node
609 is closed or after each data, comment, CDATA, or directive node.
610
611
612
613 mxmlSAXLoadFile
614 Load a file into an XML node tree using a SAX callback.
615
616 mxml_node_t * mxmlSAXLoadFile (
617 mxml_node_t *top,
618 FILE *fp,
619 mxml_load_cb_t cb,
620 mxml_sax_cb_t sax_cb,
621 void *sax_data
622 );
623
624 The nodes in the specified file are added to the specified top node.
625 If no top node is provided, the XML file MUST be well-formed with a
626 single parent node like <?xml> for the entire file. The callback func‐
627 tion returns the value type that should be used for child nodes. If
628 MXML_NO_CALLBACK is specified then all child nodes will be either
629 MXML_ELEMENT or MXML_TEXT nodes.
630
631 The constants MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK,
632 MXML_REAL_CALLBACK, and MXML_TEXT_CALLBACK are defined for loading
633 child nodes of the specified type.
634
635 The SAX callback must call mxmlRetain() for any nodes that need to be
636 kept for later use. Otherwise, nodes are deleted when the parent node
637 is closed or after each data, comment, CDATA, or directive node.
638
639
640
641 mxmlSAXLoadString
642 Load a string into an XML node tree using a SAX callback.
643
644 mxml_node_t * mxmlSAXLoadString (
645 mxml_node_t *top,
646 const char *s,
647 mxml_load_cb_t cb,
648 mxml_sax_cb_t sax_cb,
649 void *sax_data
650 );
651
652 The nodes in the specified string are added to the specified top node.
653 If no top node is provided, the XML string MUST be well-formed with a
654 single parent node like <?xml> for the entire string. The callback
655 function returns the value type that should be used for child nodes.
656 If MXML_NO_CALLBACK is specified then all child nodes will be either
657 MXML_ELEMENT or MXML_TEXT nodes.
658
659 The constants MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK,
660 MXML_REAL_CALLBACK, and MXML_TEXT_CALLBACK are defined for loading
661 child nodes of the specified type.
662
663 The SAX callback must call mxmlRetain() for any nodes that need to be
664 kept for later use. Otherwise, nodes are deleted when the parent node
665 is closed or after each data, comment, CDATA, or directive node.
666
667
668
669 mxmlSaveAllocString
670 Save an XML node tree to an allocated string.
671
672 char * mxmlSaveAllocString (
673 mxml_node_t *node,
674 mxml_save_cb_t cb
675 );
676
677 This function returns a pointer to a string containing the textual rep‐
678 resentation of the XML node tree. The string should be freed using the
679 free() function when you are done with it. NULL is returned if the
680 node would produce an empty string or if the string cannot be allo‐
681 cated.
682
683 The callback argument specifies a function that returns a whitespace
684 string or NULL before and after each element. If MXML_NO_CALLBACK is
685 specified, whitespace will only be added before MXML_TEXT nodes with
686 leading whitespace and before attribute names inside opening element
687 tags.
688
689 mxmlSaveFd
690 Save an XML tree to a file descriptor.
691
692 int mxmlSaveFd (
693 mxml_node_t *node,
694 int fd,
695 mxml_save_cb_t cb
696 );
697
698 The callback argument specifies a function that returns a whitespace
699 string or NULL before and after each element. If MXML_NO_CALLBACK is
700 specified, whitespace will only be added before MXML_TEXT nodes with
701 leading whitespace and before attribute names inside opening element
702 tags.
703
704 mxmlSaveFile
705 Save an XML tree to a file.
706
707 int mxmlSaveFile (
708 mxml_node_t *node,
709 FILE *fp,
710 mxml_save_cb_t cb
711 );
712
713 The callback argument specifies a function that returns a whitespace
714 string or NULL before and after each element. If MXML_NO_CALLBACK is
715 specified, whitespace will only be added before MXML_TEXT nodes with
716 leading whitespace and before attribute names inside opening element
717 tags.
718
719 mxmlSaveString
720 Save an XML node tree to a string.
721
722 int mxmlSaveString (
723 mxml_node_t *node,
724 char *buffer,
725 int bufsize,
726 mxml_save_cb_t cb
727 );
728
729 This function returns the total number of bytes that would be required
730 for the string but only copies (bufsize - 1) characters into the speci‐
731 fied buffer.
732
733 The callback argument specifies a function that returns a whitespace
734 string or NULL before and after each element. If MXML_NO_CALLBACK is
735 specified, whitespace will only be added before MXML_TEXT nodes with
736 leading whitespace and before attribute names inside opening element
737 tags.
738
739 mxmlSetCDATA
740 Set the element name of a CDATA node.
741
742 int mxmlSetCDATA (
743 mxml_node_t *node,
744 const char *data
745 );
746
747 The node is not changed if it is not a CDATA element node.
748
749
750
751 mxmlSetCustom
752 Set the data and destructor of a custom data node.
753
754 int mxmlSetCustom (
755 mxml_node_t *node,
756 void *data,
757 mxml_custom_destroy_cb_t destroy
758 );
759
760 The node is not changed if it is not a custom node.
761
762
763
764 mxmlSetCustomHandlers
765 Set the handling functions for custom data.
766
767 void mxmlSetCustomHandlers (
768 mxml_custom_load_cb_t load,
769 mxml_custom_save_cb_t save
770 );
771
772 The load function accepts a node pointer and a data string and must
773 return 0 on success and non-zero on error.
774
775 The save function accepts a node pointer and must return a malloc'd
776 string on success and NULL on error.
777
778 mxmlSetElement
779 Set the name of an element node.
780
781 int mxmlSetElement (
782 mxml_node_t *node,
783 const char *name
784 );
785
786 The node is not changed if it is not an element node.
787
788 mxmlSetErrorCallback
789 Set the error message callback.
790
791 void mxmlSetErrorCallback (
792 mxml_error_cb_t cb
793 );
794
795 mxmlSetInteger
796 Set the value of an integer node.
797
798 int mxmlSetInteger (
799 mxml_node_t *node,
800 int integer
801 );
802
803 The node is not changed if it is not an integer node.
804
805 mxmlSetOpaque
806 Set the value of an opaque node.
807
808 int mxmlSetOpaque (
809 mxml_node_t *node,
810 const char *opaque
811 );
812
813 The node is not changed if it is not an opaque node.
814
815 mxmlSetReal
816 Set the value of a real number node.
817
818 int mxmlSetReal (
819 mxml_node_t *node,
820 double real
821 );
822
823 The node is not changed if it is not a real number node.
824
825 mxmlSetText
826 Set the value of a text node.
827
828 int mxmlSetText (
829 mxml_node_t *node,
830 int whitespace,
831 const char *string
832 );
833
834 The node is not changed if it is not a text node.
835
836 mxmlSetTextf
837 Set the value of a text node to a formatted string.
838
839 int mxmlSetTextf (
840 mxml_node_t *node,
841 int whitespace,
842 const char *format,
843 ...
844 );
845
846 The node is not changed if it is not a text node.
847
848 mxmlSetWrapMargin
849 Set the the wrap margin when saving XML data.
850
851 void mxmlSetWrapMargin (
852 int column
853 );
854
855 Wrapping is disabled when "column" is <= 0.
856
857
858
859 mxmlWalkNext
860 Walk to the next logical node in the tree.
861
862 mxml_node_t * mxmlWalkNext (
863 mxml_node_t *node,
864 mxml_node_t *top,
865 int descend
866 );
867
868 The descend argument controls whether the first child is considered to
869 be the next node. The top node argument constrains the walk to the
870 node's children.
871
872 mxmlWalkPrev
873 Walk to the previous logical node in the tree.
874
875 mxml_node_t * mxmlWalkPrev (
876 mxml_node_t *node,
877 mxml_node_t *top,
878 int descend
879 );
880
881 The descend argument controls whether the previous node's last child is
882 considered to be the previous node. The top node argument constrains
883 the walk to the node's children.
884
886 mxml_attr_s
887 An XML element attribute value.
888
889 struct mxml_attr_s
890 {
891 char *name;
892 char *value;
893 };
894
895 mxml_custom_s
896 An XML custom value.
897
898 struct mxml_custom_s
899 {
900 void *data;
901 mxml_custom_destroy_cb_t destroy;
902 };
903
904 mxml_element_s
905 An XML element value.
906
907 struct mxml_element_s
908 {
909 mxml_attr_t *attrs;
910 char *name;
911 int num_attrs;
912 };
913
914 mxml_index_s
915 An XML node index.
916
917 struct mxml_index_s
918 {
919 int alloc_nodes;
920 char *attr;
921 int cur_node;
922 mxml_node_t **nodes;
923 int num_nodes;
924 };
925
926 mxml_node_s
927 An XML node.
928
929 struct mxml_node_s
930 {
931 struct mxml_node_s *child;
932 struct mxml_node_s *last_child;
933 struct mxml_node_s *next;
934 struct mxml_node_s *parent;
935 struct mxml_node_s *prev;
936 int ref_count;
937 mxml_type_t type;
938 void *user_data;
939 mxml_value_t value;
940 };
941
942 mxml_text_s
943 An XML text value.
944
945 struct mxml_text_s
946 {
947 char *string;
948 int whitespace;
949 };
950
952 mxml_attr_t
953 An XML element attribute value.
954
955 typedef struct mxml_attr_s mxml_attr_t;
956
957 mxml_custom_destroy_cb_t
958 Custom data destructor
959
960 typedef void(*)(void *) mxml_custom_destroy_cb_t;
961
962 mxml_custom_load_cb_t
963 Custom data load callback function
964
965 typedef int(*)(mxml_node_t *, const char *) mxml_custom_load_cb_t;
966
967 mxml_custom_save_cb_t
968 Custom data save callback function
969
970 typedef char *(*)(mxml_node_t *) mxml_custom_save_cb_t;
971
972 mxml_custom_t
973 An XML custom value.
974
975 typedef struct mxml_custom_s mxml_custom_t;
976
977 mxml_element_t
978 An XML element value.
979
980 typedef struct mxml_element_s mxml_element_t;
981
982 mxml_error_cb_t
983 Error callback function
984
985 typedef void(*)(const char *) mxml_error_cb_t;
986
987 mxml_index_t
988 An XML node index.
989
990 typedef struct mxml_index_s mxml_index_t;
991
992 mxml_load_cb_t
993 Load callback function
994
995 typedef mxml_type_t(*)(mxml_node_t *) mxml_load_cb_t;
996
997 mxml_node_t
998 An XML node.
999
1000 typedef struct mxml_node_s mxml_node_t;
1001
1002 mxml_save_cb_t
1003 Save callback function
1004
1005 typedef const char *(*)(mxml_node_t *, int) mxml_save_cb_t;
1006
1007 mxml_sax_cb_t
1008 SAX callback function
1009
1010 typedef void(*)(mxml_node_t *, mxml_sax_event_t, void *) mxml_sax_cb_t;
1011
1012 mxml_sax_event_t
1013 SAX event type.
1014
1015 typedef enum mxml_sax_event_e mxml_sax_event_t;
1016
1017 mxml_text_t
1018 An XML text value.
1019
1020 typedef struct mxml_text_s mxml_text_t;
1021
1022 mxml_value_t
1023 An XML node value.
1024
1025 typedef union mxml_value_u mxml_value_t;
1026
1028 mxml_value_u
1029 An XML node value.
1030
1031 union mxml_value_u
1032 {
1033 mxml_custom_t custom;
1034 mxml_element_t element;
1035 int integer;
1036 char *opaque;
1037 double real;
1038 mxml_text_t text;
1039 };
1040
1042 mxmldoc(1), Mini-XML Programmers Manual, http://www.minixml.org/
1043
1045 Copyright 2003-2008 by Michael Sweet.
1046
1047
1048
104910/28/09 Mini-XML API mxml(3)