1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942
|
.TH mxml 3 "Mini-XML API" "2025-01-19" "Mini-XML API"
.SH NAME
mxml \- Mini-XML API
.SH INCLUDE FILE
#include <mxml.h>
.SH LIBRARY
\-lmxml
.SH DESCRIPTION
Mini-XML is a small XML parsing library that you can use to
read XML and XML-like data files in your application without
requiring large non-standard libraries. Mini-XML only
requires an ANSI C compatible compiler (GCC works, as do
most vendors' ANSI C compilers) and a "make" program.
.PP
Mini-XML provides the following functionality:
.IP \(bu 4
Reading of UTF-8 and UTF-16 and writing of UTF-8 encoded XML files and strings.
.IP \(bu 4
Data is stored in a linked-list tree structure,
preserving the XML data hierarchy.
.IP \(bu 4
Supports arbitrary element names, attributes, and attribute
values with no preset limits, just available memory.
.IP \(bu 4
Supports integer, real, opaque ("CDATA"), and text data types in
"leaf" nodes.
.IP \(bu 4
Functions for creating, indexing, and managing trees of data.
.IP \(bu 4
"Find" and "walk" functions for easily locating and navigating
trees of data.
.PP
Mini-XML doesn't do validation or other types of processing
on the data based upon schema files or other sources of
definition information, nor does it support character
entities other than those required by the XML
specification.
.SH USING MINI-XML
Mini-XML provides a single header file which you include:
.nf
#include <mxml.h>
.fi
.PP
Nodes are defined by the "mxml_node_t" structure; the "type"
member defines the node type (element, integer, opaque,
real, or text) which determines which value you want to look
at in the "value" union. New nodes can be created using the
"mxmlNewElement()", "mxmlNewInteger()", "mxmlNewOpaque()",
"mxmlNewReal()", and "mxmlNewText()" functions. Only
elements can have child nodes, and the top node must be an
element, usually "?xml".
.PP
You load an XML file using the "mxmlLoadFile()" function:
.nf
FILE *fp;
mxml_node_t *tree;
fp = fopen("filename.xml", "r");
tree = mxmlLoadFile(NULL, fp, MXML_NO_CALLBACK);
fclose(fp);
.fi
.PP
Similarly, you save an XML file using the "mxmlSaveFile()"
function:
.nf
FILE *fp;
mxml_node_t *tree;
fp = fopen("filename.xml", "w");
mxmlSaveFile(tree, fp, MXML_NO_CALLBACK);
fclose(fp);
.fi
.PP
The "mxmlLoadString()", "mxmlSaveAllocString()", and
"mxmlSaveString()" functions load XML node trees from and save
XML node trees to strings:
.nf
char buffer[8192];
char *ptr;
mxml_node_t *tree;
...
tree = mxmlLoadString(NULL, buffer, MXML_NO_CALLBACK);
...
mxmlSaveString(tree, buffer, sizeof(buffer),
MXML_NO_CALLBACK);
...
ptr = mxmlSaveAllocString(tree, MXML_NO_CALLBACK);
.fi
.PP
You can find a named element/node using the "mxmlFindElement()"
function:
.nf
mxml_node_t *node = mxmlFindElement(tree, tree, "name",
"attr", "value",
MXML_DESCEND);
.fi
.PP
The "name", "attr", and "value" arguments can be passed as
NULL to act as wildcards, e.g.:
.nf
/* Find the first "a" element */
node = mxmlFindElement(tree, tree, "a", NULL, NULL,
MXML_DESCEND);
/* Find the first "a" element with "href" attribute */
node = mxmlFindElement(tree, tree, "a", "href", NULL,
MXML_DESCEND);
/* Find the first "a" element with "href" to a URL */
node = mxmlFindElement(tree, tree, "a", "href",
"http://www.easysw.com/~mike/mxml/",
MXML_DESCEND);
/* Find the first element with a "src" attribute*/
node = mxmlFindElement(tree, tree, NULL, "src", NULL,
MXML_DESCEND);
/* Find the first element with a "src" = "foo.jpg" */
node = mxmlFindElement(tree, tree, NULL, "src",
"foo.jpg", MXML_DESCEND);
.fi
.PP
You can also iterate with the same function:
.nf
mxml_node_t *node;
for (node = mxmlFindElement(tree, tree, "name", NULL,
NULL, MXML_DESCEND);
node != NULL;
node = mxmlFindElement(node, tree, "name", NULL,
NULL, MXML_DESCEND))
{
... do something ...
}
.fi
.PP
To find the value of a specific node in the tree, use the "mxmlFindPath()"
function:
.nf
mxml_node_t *value = mxmlFindPath(tree, "path/to/*/foo/bar");
.fi
.PP
The "mxmlGetInteger()", "mxmlGetOpaque()", "mxmlGetReal()", and "mxmlGetText()"
functions retrieve the value from a node:
.nf
mxml_node_t *node;
long intvalue = mxmlGetInteger(node);
const char *opaquevalue = mxmlGetOpaque(node);
double realvalue = mxmlGetReal(node);
bool whitespacevalue;
const char *textvalue = mxmlGetText(node, &whitespacevalue);
.fi
.PP
Finally, once you are done with the XML data, use the
"mxmlDelete()" function to recursively free the memory that
is used for a particular node or the entire tree:
.nf
mxmlDelete(tree);
.fi
.SH ENUMERATIONS
.SS mxml_add_e
\fImxmlAdd\fR add values
.TP 5
MXML_ADD_AFTER
.br
Add node after specified node
.TP 5
MXML_ADD_BEFORE
.br
Add node before specified node
.SS mxml_descend_e
\fImxmlFindElement\fR, \fImxmlWalkNext\fR, and \fImxmlWalkPrev\fR descend values
.TP 5
MXML_DESCEND_ALL
.br
Descend when finding/walking
.TP 5
MXML_DESCEND_FIRST
.br
Descend for first find
.TP 5
MXML_DESCEND_NONE
.br
Don't descend when finding/walking
.SS mxml_sax_event_e
SAX event type.
.TP 5
MXML_SAX_EVENT_CDATA
.br
CDATA node
.TP 5
MXML_SAX_EVENT_COMMENT
.br
Comment node
.TP 5
MXML_SAX_EVENT_DATA
.br
Data node
.TP 5
MXML_SAX_EVENT_DECLARATION
.br
Declaration node
.TP 5
MXML_SAX_EVENT_DIRECTIVE
.br
Processing instruction node
.TP 5
MXML_SAX_EVENT_ELEMENT_CLOSE
.br
Element closed
.TP 5
MXML_SAX_EVENT_ELEMENT_OPEN
.br
Element opened
.SS mxml_type_e
The XML node type.
.TP 5
MXML_TYPE_CDATA
.br
CDATA value ("
.URL [CDATA[...]] [CDATA[...]]
")
.TP 5
MXML_TYPE_COMMENT
.br
Comment ("
.URL !--...-- !--...--
")
.TP 5
MXML_TYPE_CUSTOM
.br
Custom data
.TP 5
MXML_TYPE_DECLARATION
.br
Declaration ("
.URL !... !...
")
.TP 5
MXML_TYPE_DIRECTIVE
.br
Processing instruction ("
.URL ?...? ?...?
")
.TP 5
MXML_TYPE_ELEMENT
.br
XML element with attributes
.TP 5
MXML_TYPE_IGNORE
.br
Ignore/throw away node
.TP 5
MXML_TYPE_INTEGER
.br
Integer value
.TP 5
MXML_TYPE_OPAQUE
.br
Opaque string
.TP 5
MXML_TYPE_REAL
.br
Real value
.TP 5
MXML_TYPE_TEXT
.br
Text fragment
.SS mxml_ws_e
Whitespace periods
.TP 5
MXML_WS_AFTER_CLOSE
.br
Callback for after close tag
.TP 5
MXML_WS_AFTER_OPEN
.br
Callback for after open tag
.TP 5
MXML_WS_BEFORE_CLOSE
.br
Callback for before close tag
.TP 5
MXML_WS_BEFORE_OPEN
.br
Callback for before open tag
.SH FUNCTIONS
.SS mxmlAdd
Add a node to a tree.
.PP
.nf
void mxmlAdd (
mxml_node_t *parent,
mxml_add_t add,
mxml_node_t *child,
mxml_node_t *node
);
.fi
.PP
This function adds the specified node \fBnode\fR to the parent. If the \fBchild\fR
argument is not \fBNULL\fR, the new node is added before or after the specified
child depending on the value of the \fBadd\fR argument. If the \fBchild\fR argument
is \fBNULL\fR, the new node is placed at the beginning of the child list
(\fBMXML_ADD_BEFORE\fR) or at the end of the child list (\fBMXML_ADD_AFTER\fR).
.SS mxmlDelete
Delete a node and all of its children.
.PP
.nf
void mxmlDelete (
mxml_node_t *node
);
.fi
.PP
This function deletes the node \fBnode\fR and all of its children. If the
specified node has a parent, this function first removes the node from its
parent using the \fImxmlRemove\fR function.
.SS mxmlElementClearAttr
Remove an attribute from an element.
.PP
.nf
void mxmlElementClearAttr (
mxml_node_t *node,
const char *name
);
.fi
.PP
This function removes the attribute \fBname\fR from the element \fBnode\fR.
.SS mxmlElementGetAttr
Get the value of an attribute.
.PP
.nf
const char * mxmlElementGetAttr (
mxml_node_t *node,
const char *name
);
.fi
.PP
This function gets the value for the attribute \fBname\fR from the element
\fBnode\fR. \fBNULL\fR is returned if the node is not an element or the named
attribute does not exist.
.SS mxmlElementGetAttrByIndex
Get an attribute by index.
.PP
.nf
const char * mxmlElementGetAttrByIndex (
mxml_node_t *node,
size_t idx,
const char **name
);
.fi
.PP
This function returned the Nth (\fBidx\fR) attribute for element \fBnode\fR. The
attribute name is optionallly returned in the \fBname\fR argument. \fBNULL\fR is
returned if node is not an element or the specified index is out of range.
.SS mxmlElementGetAttrCount
Get the number of element attributes.
.PP
.nf
size_t mxmlElementGetAttrCount (
mxml_node_t *node
);
.fi
.PP
This function returns the number of attributes for the element \fBnode\fR. \fB0\fR
is returned if the node is not an element or there are no attributes for the
element.
.SS mxmlElementSetAttr
Set an attribute for an element.
.PP
.nf
void mxmlElementSetAttr (
mxml_node_t *node,
const char *name,
const char *value
);
.fi
.PP
This function sets attribute \fBname\fR to the string \fBvalue\fR for the element
\fBnode\fR. If the named attribute already exists, the value of the attribute
is replaced by the new string value. The string value is copied.
.SS mxmlElementSetAttrf
Set an attribute with a formatted value.
.PP
.nf
void mxmlElementSetAttrf (
mxml_node_t *node,
const char *name,
const char *format,
...
);
.fi
.PP
This function sets attribute \fBname\fR to the formatted value of \fBformat\fR for
the element \fBnode\fR. If the named attribute already exists, the value of the
attribute is replaced by the new formatted string value.
.SS mxmlFindElement
Find the named element.
.PP
.nf
mxml_node_t * mxmlFindElement (
mxml_node_t *node,
mxml_node_t *top,
const char *element,
const char *attr,
const char *value,
mxml_descend_t descend
);
.fi
.PP
This function finds the named element \fBelement\fR in XML tree \fBtop\fR starting at
node \fBnode\fR. The search is constrained by element name \fBelement\fR, attribute
name \fBattr\fR, and attribute value \fBvalue\fR - \fBNULL\fR names or values are treated
as wildcards, so different kinds of searches can be implemented by looking
for all elements of a given name or all elements with a specific attribute.
.PP
The \fBdescend\fR argument determines whether the search descends into child
nodes; normally you will use \fBMXML_DESCEND_FIRST\fR for the initial search and
\fBMXML_DESCEND_NONE\fR to find additional direct descendents of the node.
.SS mxmlFindPath
Find a node with the given path.
.PP
.nf
mxml_node_t * mxmlFindPath (
mxml_node_t *top,
const char *path
);
.fi
.PP
This function finds a node in XML tree \fBtop\fR using a slash-separated list of
element names in \fBpath\fR. The name "\fI" is considered a wildcard for one or
more levels of elements, for example, "foo/one/two", "bar/two/one", "\fR/one",
and so forth.
.PP
The first child node of the found node is returned if the given node has
children and the first child is a value node.
.SS mxmlGetCDATA
Get the value for a CDATA node.
.PP
.nf
const char * mxmlGetCDATA (
mxml_node_t *node
);
.fi
.PP
This function gets the string value of a CDATA node. \fBNULL\fR is returned if
the node is not a CDATA element.
.SS mxmlGetComment
Get the value for a comment node.
.PP
.nf
const char * mxmlGetComment (
mxml_node_t *node
);
.fi
.PP
This function gets the string value of a comment node. \fBNULL\fR is returned
if the node is not a comment.
.SS mxmlGetCustom
Get the value for a custom node.
.PP
.nf
const void * mxmlGetCustom (
mxml_node_t *node
);
.fi
.PP
This function gets the binary value of a custom node. \fBNULL\fR is returned if
the node (or its first child) is not a custom value node.
.SS mxmlGetDeclaration
Get the value for a declaration node.
.PP
.nf
const char * mxmlGetDeclaration (
mxml_node_t *node
);
.fi
.PP
This function gets the string value of a declaraction node. \fBNULL\fR is
returned if the node is not a declaration.
.SS mxmlGetDirective
Get the value for a processing instruction node.
.PP
.nf
const char * mxmlGetDirective (
mxml_node_t *node
);
.fi
.PP
This function gets the string value of a processing instruction. \fBNULL\fR is
returned if the node is not a processing instruction.
.SS mxmlGetElement
Get the name for an element node.
.PP
.nf
const char * mxmlGetElement (
mxml_node_t *node
);
.fi
.PP
This function gets the name of an element node. \fBNULL\fR is returned if the
node is not an element node.
.SS mxmlGetFirstChild
Get the first child of a node.
.PP
.nf
mxml_node_t * mxmlGetFirstChild (
mxml_node_t *node
);
.fi
.PP
This function gets the first child of a node. \fBNULL\fR is returned if the node
has no children.
.SS mxmlGetInteger
Get the integer value from the specified node or its
first child.
.PP
.nf
long mxmlGetInteger (
mxml_node_t *node
);
.fi
.PP
This function gets the value of an integer node. \fB0\fR is returned if the node
(or its first child) is not an integer value node.
.SS mxmlGetLastChild
Get the last child of a node.
.PP
.nf
mxml_node_t * mxmlGetLastChild (
mxml_node_t *node
);
.fi
.PP
This function gets the last child of a node. \fBNULL\fR is returned if the node
has no children.
.SS mxmlGetNextSibling
.PP
.nf
mxml_node_t * mxmlGetNextSibling (
mxml_node_t *node
);
.fi
.SS mxmlGetOpaque
Get an opaque string value for a node or its first child.
.PP
.nf
const char * mxmlGetOpaque (
mxml_node_t *node
);
.fi
.PP
This function gets the string value of an opaque node. \fBNULL\fR is returned if
the node (or its first child) is not an opaque value node.
.SS mxmlGetParent
Get the parent node.
.PP
.nf
mxml_node_t * mxmlGetParent (
mxml_node_t *node
);
.fi
.PP
This function gets the parent of a node. \fBNULL\fR is returned for a root node.
.SS mxmlGetPrevSibling
Get the previous node for the current parent.
.PP
.nf
mxml_node_t * mxmlGetPrevSibling (
mxml_node_t *node
);
.fi
.PP
This function gets the previous node for the current parent. \fBNULL\fR is
returned if this is the first child for the current parent.
.SS mxmlGetReal
Get the real value for a node or its first child.
.PP
.nf
double mxmlGetReal (
mxml_node_t *node
);
.fi
.PP
This function gets the value of a real value node. \fB0.0\fR is returned if the
node (or its first child) is not a real value node.
.SS mxmlGetRefCount
Get the current reference (use) count for a node.
.PP
.nf
size_t mxmlGetRefCount (
mxml_node_t *node
);
.fi
.PP
The initial reference count of new nodes is 1. Use the \fImxmlRetain\fR
and \fImxmlRelease\fR functions to increment and decrement a node's
reference count.
.SS mxmlGetText
Get the text value for a node or its first child.
.PP
.nf
const char * mxmlGetText (
mxml_node_t *node,
bool *whitespace
);
.fi
.PP
This function gets the string and whitespace values of a text node. \fBNULL\fR
and \fBfalse\fR are returned if the node (or its first child) is not a text node.
The \fBwhitespace\fR argument can be \fBNULL\fR if you don't want to know the
whitespace value.
.PP
Note: Text nodes consist of whitespace-delimited words. You will only get
single words of text when reading an XML file with \fBMXML_TYPE_TEXT\fR nodes.
If you want the entire string between elements in the XML file, you MUST read
the XML file with \fBMXML_TYPE_OPAQUE\fR nodes and get the resulting strings
using the \fImxmlGetOpaque\fR function instead.
.SS mxmlGetType
Get the node type.
.PP
.nf
mxml_type_t mxmlGetType (
mxml_node_t *node
);
.fi
.PP
This function gets the type of \fBnode\fR. \fBMXML_TYPE_IGNORE\fR is returned if
\fBnode\fR is \fBNULL\fR.
.SS mxmlGetUserData
Get the user data pointer for a node.
.PP
.nf
void * mxmlGetUserData (
mxml_node_t *node
);
.fi
.PP
This function gets the user data pointer associated with \fBnode\fR.
.SS mxmlIndexDelete
Delete an index.
.PP
.nf
void mxmlIndexDelete (
mxml_index_t *ind
);
.fi
.SS mxmlIndexEnum
Return the next node in the index.
.PP
.nf
mxml_node_t * mxmlIndexEnum (
mxml_index_t *ind
);
.fi
.PP
This function returns the next node in index \fBind\fR.
.PP
You should call \fImxmlIndexReset\fR prior to using this function to get
the first node in the index. Nodes are returned in the sorted order of the
index.
.SS mxmlIndexFind
Find the next matching node.
.PP
.nf
mxml_node_t * mxmlIndexFind (
mxml_index_t *ind,
const char *element,
const char *value
);
.fi
.PP
This function finds the next matching node in index \fBind\fR.
.PP
You should call \fImxmlIndexReset\fR prior to using this function for
the first time with a particular set of \fBelement\fR and \fBvalue\fR
strings. Passing \fBNULL\fR for both \fBelement\fR and \fBvalue\fR is equivalent
to calling \fImxmlIndexEnum\fR.
.SS mxmlIndexGetCount
Get the number of nodes in an index.
.PP
.nf
size_t mxmlIndexGetCount (
mxml_index_t *ind
);
.fi
.SS mxmlIndexNew
Create a new index.
.PP
.nf
mxml_index_t * mxmlIndexNew (
mxml_node_t *node,
const char *element,
const char *attr
);
.fi
.PP
This function creates a new index for XML tree \fBnode\fR.
.PP
The index will contain all nodes that contain the named element and/or
attribute. If both \fBelement\fR and \fBattr\fR are \fBNULL\fR, then the index will
contain a sorted list of the elements in the node tree. Nodes are
sorted by element name and optionally by attribute value if the \fBattr\fR
argument is not \fBNULL\fR.
.SS mxmlIndexReset
Reset the enumeration/find pointer in the index and
return the first node in the index.
.PP
.nf
mxml_node_t * mxmlIndexReset (
mxml_index_t *ind
);
.fi
.PP
This function resets the enumeration/find pointer in index \fBind\fR and should
be called prior to using \fImxmlIndexEnum\fR or \fImxmlIndexFind\fR for the
first time.
.SS mxmlLoadFd
Load a file descriptor into an XML node tree.
.PP
.nf
mxml_node_t * mxmlLoadFd (
mxml_node_t *top,
mxml_options_t *options,
int fd
);
.fi
.PP
This function loads the file descriptor \fBfd\fR into an XML node tree. The
nodes in the specified file are added to the specified node \fBtop\fR - if \fBNULL\fR
the XML file MUST be well-formed with a single parent processing instruction
node like \fB<?xml version="1.0"?>\fR at the start of the file.
.PP
Load options are provides via the \fBoptions\fR argument. If \fBNULL\fR, all values
will be loaded into \fBMXML_TYPE_TEXT\fR nodes. Use the \fImxmlOptionsNew\fR
function to create options when loading XML data.
.SS mxmlLoadFile
Load a file into an XML node tree.
.PP
.nf
mxml_node_t * mxmlLoadFile (
mxml_node_t *top,
mxml_options_t *options,
FILE *fp
);
.fi
.PP
This function loads the \fBFILE\fR pointer \fBfp\fR into an XML node tree. The
nodes in the specified file are added to the specified node \fBtop\fR - if \fBNULL\fR
the XML file MUST be well-formed with a single parent processing instruction
node like \fB<?xml version="1.0"?>\fR at the start of the file.
.PP
Load options are provides via the \fBoptions\fR argument. If \fBNULL\fR, all values
will be loaded into \fBMXML_TYPE_TEXT\fR nodes. Use the \fImxmlOptionsNew\fR
function to create options when loading XML data.
.SS mxmlLoadFilename
Load a file into an XML node tree.
.PP
.nf
mxml_node_t * mxmlLoadFilename (
mxml_node_t *top,
mxml_options_t *options,
const char *filename
);
.fi
.PP
This function loads the named file \fBfilename\fR into an XML node tree. The
nodes in the specified file are added to the specified node \fBtop\fR - if \fBNULL\fR
the XML file MUST be well-formed with a single parent processing instruction
node like \fB<?xml version="1.0"?>\fR at the start of the file.
.PP
Load options are provides via the \fBoptions\fR argument. If \fBNULL\fR, all values
will be loaded into \fBMXML_TYPE_TEXT\fR nodes. Use the \fImxmlOptionsNew\fR
function to create options when loading XML data.
.SS mxmlLoadIO
Load an XML node tree using a read callback.
.PP
.nf
mxml_node_t * mxmlLoadIO (
mxml_node_t *top,
mxml_options_t *options,
mxml_io_cb_t io_cb,
void *io_cbdata
);
.fi
.PP
This function loads data into an XML node tree using a read callback. The
nodes in the specified file are added to the specified node \fBtop\fR - if \fBNULL\fR
the XML file MUST be well-formed with a single parent processing instruction
node like \fB<?xml version="1.0"?>\fR at the start of the file.
.PP
Load options are provides via the \fBoptions\fR argument. If \fBNULL\fR, all values
will be loaded into \fBMXML_TYPE_TEXT\fR nodes. Use the \fImxmlOptionsNew\fR
function to create options when loading XML data.
.PP
The read callback function \fBio_cb\fR is called to read a number of bytes from
the source. The callback data pointer \fBio_cbdata\fR is passed to the read
callback with a pointer to a buffer and the maximum number of bytes to read,
for example:
.PP
\fB`\fRc
size_t my_io_cb(void \fIcbdata, void \fRbuffer, size_t bytes)
{
... copy up to "bytes" bytes into buffer ...
... return the number of bytes "read" or 0 on error ...
}
\fB`\fR
.SS mxmlLoadString
Load a string into an XML node tree.
.PP
.nf
mxml_node_t * mxmlLoadString (
mxml_node_t *top,
mxml_options_t *options,
const char *s
);
.fi
.PP
This function loads the string into an XML node tree. The nodes in the
specified file are added to the specified node \fBtop\fR - if \fBNULL\fR the XML file
MUST be well-formed with a single parent processing instruction node like
\fB<?xml version="1.0"?>\fR at the start of the file.
.PP
Load options are provides via the \fBoptions\fR argument. If \fBNULL\fR, all values
will be loaded into \fBMXML_TYPE_TEXT\fR nodes. Use the \fImxmlOptionsNew\fR
function to create options when loading XML data.
.SS mxmlNewCDATA
Create a new CDATA node.
.PP
.nf
mxml_node_t * mxmlNewCDATA (
mxml_node_t *parent,
const char *data
);
.fi
.PP
The new CDATA node is added to the end of the specified parent's child
list. The constant \fBNULL\fR can be used to specify that the new CDATA node
has no parent. The data string must be nul-terminated and is copied into the
new node.
.SS mxmlNewCDATAf
Create a new formatted CDATA node.
.PP
.nf
mxml_node_t * mxmlNewCDATAf (
mxml_node_t *parent,
const char *format,
...
);
.fi
.PP
The new CDATA node is added to the end of the specified parent's child list.
The constant \fBNULL\fR can be used to specify that the new opaque string node
has no parent. The format string must be nul-terminated and is formatted
into the new node.
.SS mxmlNewComment
Create a new comment node.
.PP
.nf
mxml_node_t * mxmlNewComment (
mxml_node_t *parent,
const char *comment
);
.fi
.PP
The new comment node is added to the end of the specified parent's child
list. The constant \fBNULL\fR can be used to specify that the new comment node
has no parent. The comment string must be nul-terminated and is copied into
the new node.
.SS mxmlNewCommentf
Create a new formatted comment string node.
.PP
.nf
mxml_node_t * mxmlNewCommentf (
mxml_node_t *parent,
const char *format,
...
);
.fi
.PP
The new comment string node is added to the end of the specified parent's
child list. The constant \fBNULL\fR can be used to specify that the new opaque
string node has no parent. The format string must be nul-terminated and is
formatted into the new node.
.SS mxmlNewCustom
Create a new custom data node.
.PP
.nf
mxml_node_t * mxmlNewCustom (
mxml_node_t *parent,
void *data,
mxml_custfree_cb_t free_cb,
void *free_cbdata
);
.fi
.PP
The new custom node is added to the end of the specified parent's child
list. The \fBfree_cb\fR argument specifies a function to call to free the custom
data when the node is deleted.
.SS mxmlNewDeclaration
Create a new declaraction node.
.PP
.nf
mxml_node_t * mxmlNewDeclaration (
mxml_node_t *parent,
const char *declaration
);
.fi
.PP
The new declaration node is added to the end of the specified parent's child
list. The constant \fBNULL\fR can be used to specify that the new
declaration node has no parent. The declaration string must be nul-
terminated and is copied into the new node.
.SS mxmlNewDeclarationf
Create a new formatted declaration node.
.PP
.nf
mxml_node_t * mxmlNewDeclarationf (
mxml_node_t *parent,
const char *format,
...
);
.fi
.PP
The new declaration node is added to the end of the specified parent's
child list. The constant \fBNULL\fR can be used to specify that
the new opaque string node has no parent. The format string must be
nul-terminated and is formatted into the new node.
.SS mxmlNewDirective
Create a new processing instruction node.
.PP
.nf
mxml_node_t * mxmlNewDirective (
mxml_node_t *parent,
const char *directive
);
.fi
.PP
The new processing instruction node is added to the end of the specified
parent's child list. The constant \fBNULL\fR can be used to specify that the new
processing instruction node has no parent. The data string must be
nul-terminated and is copied into the new node.
.SS mxmlNewDirectivef
Create a new formatted processing instruction node.
.PP
.nf
mxml_node_t * mxmlNewDirectivef (
mxml_node_t *parent,
const char *format,
...
);
.fi
.PP
The new processing instruction node is added to the end of the specified
parent's child list. The constant \fBNULL\fR can be used to specify that the new
opaque string node has no parent. The format string must be
nul-terminated and is formatted into the new node.
.SS mxmlNewElement
Create a new element node.
.PP
.nf
mxml_node_t * mxmlNewElement (
mxml_node_t *parent,
const char *name
);
.fi
.PP
The new element node is added to the end of the specified parent's child
list. The constant \fBNULL\fR can be used to specify that the new element node
has no parent.
.SS mxmlNewInteger
Create a new integer node.
.PP
.nf
mxml_node_t * mxmlNewInteger (
mxml_node_t *parent,
long integer
);
.fi
.PP
The new integer node is added to the end of the specified parent's child
list. The constant \fBNULL\fR can be used to specify that the new integer node
has no parent.
.SS mxmlNewOpaque
Create a new opaque string.
.PP
.nf
mxml_node_t * mxmlNewOpaque (
mxml_node_t *parent,
const char *opaque
);
.fi
.PP
The new opaque string node is added to the end of the specified parent's
child list. The constant \fBNULL\fR can be used to specify that the new opaque
string node has no parent. The opaque string must be nul-terminated and is
copied into the new node.
.SS mxmlNewOpaquef
Create a new formatted opaque string node.
.PP
.nf
mxml_node_t * mxmlNewOpaquef (
mxml_node_t *parent,
const char *format,
...
);
.fi
.PP
The new opaque string node is added to the end of the specified parent's
child list. The constant \fBNULL\fR can be used to specify that the new opaque
string node has no parent. The format string must be nul-terminated and is
formatted into the new node.
.SS mxmlNewReal
Create a new real number node.
.PP
.nf
mxml_node_t * mxmlNewReal (
mxml_node_t *parent,
double real
);
.fi
.PP
The new real number node is added to the end of the specified parent's
child list. The constant \fBNULL\fR can be used to specify that the new real
number node has no parent.
.SS mxmlNewText
Create a new text fragment node.
.PP
.nf
mxml_node_t * mxmlNewText (
mxml_node_t *parent,
bool whitespace,
const char *string
);
.fi
.PP
The new text node is added to the end of the specified parent's child
list. The constant \fBNULL\fR can be used to specify that the new text node has
no parent. The whitespace parameter is used to specify whether leading
whitespace is present before the node. The text string must be
nul-terminated and is copied into the new node.
.SS mxmlNewTextf
Create a new formatted text fragment node.
.PP
.nf
mxml_node_t * mxmlNewTextf (
mxml_node_t *parent,
bool whitespace,
const char *format,
...
);
.fi
.PP
The new text node is added to the end of the specified parent's child
list. The constant \fBNULL\fR can be used to specify that the new text node has
no parent. The whitespace parameter is used to specify whether leading
whitespace is present before the node. The format string must be
nul-terminated and is formatted into the new node.
.SS mxmlNewXML
Create a new XML document tree.
.PP
.nf
mxml_node_t * mxmlNewXML (
const char *version
);
.fi
.PP
The "version" argument specifies the version number to put in the
?xml directive node. If \fBNULL\fR, version "1.0" is assumed.
.SS mxmlOptionsDelete
Free load/save options.
.PP
.nf
void mxmlOptionsDelete (
mxml_options_t *options
);
.fi
.SS mxmlOptionsNew
Allocate load/save options.
.PP
.nf
mxml_options_t * mxmlOptionsNew (void);
.fi
.PP
This function creates a new set of load/save options to use with the
\fImxmlLoadFd\fR, \fImxmlLoadFile\fR, \fImxmlLoadFilename\fR,
\fImxmlLoadIO\fR, \fImxmlLoadString\fR, \fImxmlSaveAllocString\fR,
\fImxmlSaveFd\fR, \fImxmlSaveFile\fR, \fImxmlSaveFilename\fR,
\fImxmlSaveIO\fR, and \fImxmlSaveString\fR functions. Options can be
reused for multiple calls to these functions and should be freed using the
\fImxmlOptionsDelete\fR function.
.PP
The default load/save options load values using the constant type
\fBMXML_TYPE_TEXT\fR and save XML data with a wrap margin of 72 columns.
The various \fBmxmlOptionsSet\fR functions are used to change the defaults,
for example:
.PP
.nf
mxml_options_t *options = mxmlOptionsNew();
/* Load values as opaque strings */
mxmlOptionsSetTypeValue(options, MXML_TYPE_OPAQUE);
.fi
Note: The most common programming error when using the Mini-XML library is
to load an XML file using the \fBMXML_TYPE_TEXT\fR node type, which returns
inline text as a series of whitespace-delimited words, instead of using the
\fBMXML_TYPE_OPAQUE\fR node type which returns the inline text as a single string
(including whitespace).
.SS mxmlOptionsSetCustomCallbacks
Set the custom data callbacks.
.PP
.nf
void mxmlOptionsSetCustomCallbacks (
mxml_options_t *options,
mxml_custload_cb_t load_cb,
mxml_custsave_cb_t save_cb,
void *cbdata
);
.fi
.PP
This function sets the callbacks that are used for loading and saving custom
data types. The load callback \fBload_cb\fR accepts the callback data pointer
\fBcbdata\fR, a node pointer, and a data string and returns \fBtrue\fR on success and
\fBfalse\fR on error, for example:
.PP
\fB`\fRc
typedef struct
{
unsigned year, /\fI Year \fR/
month, /\fI Month \fR/
day, /\fI Day \fR/
hour, /\fI Hour \fR/
minute, /\fI Minute \fR/
second; /\fI Second \fR/
time_t unix; /\fI UNIX time \fR/
} iso_date_time_t;
.PP
void
my_custom_free_cb(void \fIcbdata, void \fRdata)
{
free(data);
}
.PP
bool
my_custom_load_cb(void \fIcbdata, mxml_node_t \fRnode, const char \fIdata)
{
iso_date_time_t \fRdt;
struct tm tmdata;
.PP
/\fI Allocate custom data structure ... \fR/
dt = calloc(1, sizeof(iso_date_time_t));
.PP
/\fI Parse the data string... \fR/
if (sscanf(data, "%u-%u-%uT%u:%u:%uZ", &(dt->year), &(dt->month),
&(dt->day), &(dt->hour), &(dt->minute), &(dt->second)) != 6)
{
/\fI Unable to parse date and time numbers... \fR/
free(dt);
return (false);
}
.PP
/\fI Range check values... \fR/
if (dt->month
.URL 1 || dt- 1 || dt-
month > 12 || dt->day
.URL 1 || dt- 1 || dt-
day > 31 ||
dt->hour
.URL 0 || dt- 0 || dt-
hour > 23 || dt->minute
.URL 0 || dt- 0 || dt-
minute > 59 ||
dt->second
.URL 0 || dt- 0 || dt-
second > 60)
{
/\fI Date information is out of range... \fR/
free(dt);
return (false);
}
.PP
/\fI Convert ISO time to UNIX time in seconds... \fR/
tmdata.tm_year = dt->year - 1900;
tmdata.tm_mon = dt->month - 1;
tmdata.tm_day = dt->day;
tmdata.tm_hour = dt->hour;
tmdata.tm_min = dt->minute;
tmdata.tm_sec = dt->second;
.PP
dt->unix = gmtime(&tmdata);
.PP
/\fI Set custom data and free function... \fR/
mxmlSetCustom(node, data, my_custom_free, /\fIcbdata\fR/NULL);
.PP
/\fI Return with no errors... \fR/
return (true);
}
.nf
The save callback `save_cb` accepts the callback data pointer `cbdata` and a
node pointer and returns a malloc'd string on success and `NULL` on error,
for example:
```c
char *
my_custom_save_cb(void *cbdata, mxml_node_t *node)
{
char data[255];
iso_date_time_t *dt;
/* Get the custom data structure */
dt = (iso_date_time_t *)mxmlGetCustom(node);
/* Generate string version of the date/time... */
snprintf(data, sizeof(data), "%04u-%02u-%02uT%02u:%02u:%02uZ",
dt->year, dt->month, dt->day, dt->hour, dt->minute, dt->second);
/* Duplicate the string and return... */
return (strdup(data));
}
.fi
.SS mxmlOptionsSetEntityCallback
Set the entity lookup callback to use when loading XML data.
.PP
.nf
void mxmlOptionsSetEntityCallback (
mxml_options_t *options,
mxml_entity_cb_t cb,
void *cbdata
);
.fi
.PP
This function sets the callback that is used to lookup named XML character
entities when loading XML data. The callback function \fBcb\fR accepts the
callback data pointer \fBcbdata\fR and the entity name. The function returns a
Unicode character value or \fB-1\fR if the entity is not known. For example, the
following entity callback supports the "euro" entity:
.PP
\fB`\fRc
int my_entity_cb(void \fIcbdata, const char \fRname)
{
if (!strcmp(name, "euro"))
return (0x20ac);
else
return (-1);
}
.nf
Mini-XML automatically supports the "amp", "gt", "lt", and "quot" character
entities which are required by the base XML specification.
.fi
char *data)
{
iso_date_time_t
.SS mxmlOptionsSetErrorCallback
Set the error message callback.
.PP
.nf
void mxmlOptionsSetErrorCallback (
mxml_options_t *options,
mxml_error_cb_t cb,
void *cbdata
);
.fi
.PP
This function sets a function to use when reporting errors. The callback
\fBcb\fR accepts the data pointer \fBcbdata\fR and a string pointer containing the
error message:
.PP
\fB`\fRc
void my_error_cb(void \fIcbdata, const char \fRmessage)
{
fprintf(stderr, "myprogram: %sn", message);
}
.nf
The default error callback writes the error message to the `stderr` file.
.fi
ack supports the "euro" entity:
.PP
\fB`\fR
.SS mxmlOptionsSetSAXCallback
Set the SAX callback to use when reading XML data.
.PP
.nf
void mxmlOptionsSetSAXCallback (
mxml_options_t *options,
mxml_sax_cb_t cb,
void *cbdata
);
.fi
.PP
This function sets a SAX callback to use when reading XML data. The SAX
callback function \fBcb\fR and associated callback data \fBcbdata\fR are used to
enable the Simple API for XML streaming mode. The callback is called as the
XML node tree is parsed and receives the \fBcbdata\fR pointer, the \fBmxml_node_t\fR
pointer, and an event code. The function returns \fBtrue\fR to continue
processing or \fBfalse\fR to stop:
.PP
\fB`\fRc
bool
sax_cb(void \fIcbdata, mxml_node_t \fRnode,
mxml_sax_event_t event)
{
... do something ...
.PP
/\fI Continue processing... \fR/
return (true);
}
.nf
The event will be one of the following:
- `MXML_SAX_EVENT_CDATA`: CDATA was just read.
- `MXML_SAX_EVENT_COMMENT`: A comment was just read.
- `MXML_SAX_EVENT_DATA`: Data (integer, opaque, real, or text) was just read.
- `MXML_SAX_EVENT_DECLARATION`: A declaration was just read.
- `MXML_SAX_EVENT_DIRECTIVE`: A processing directive/instruction was just read.
- `MXML_SAX_EVENT_ELEMENT_CLOSE` - A close element was just read (`</element>`)
- `MXML_SAX_EVENT_ELEMENT_OPEN` - An open element was just read (`<element>`)
Elements are *released* after the close element is processed. All other nodes
are released after they are processed. The SAX callback can *retain* the node
using the [mxmlRetain](@@) function.
.fi
/* Date information is out of range...
.SS mxmlOptionsSetTypeCallback
Set the type callback for child/value nodes.
.PP
.nf
void mxmlOptionsSetTypeCallback (
mxml_options_t *options,
mxml_type_cb_t cb,
void *cbdata
);
.fi
.PP
The load callback function \fBcb\fR is called to obtain the node type child/value
nodes and receives the \fBcbdata\fR pointer and the \fBmxml_node_t\fR pointer, for
example:
.PP
\fB`\fRc
mxml_type_t
my_type_cb(void \fIcbdata, mxml_node_t \fRnode)
{
const char \fItype;
/\fR
\fI You can lookup attributes and/or use the element name,
\fR hierarchy, etc...
*/
.PP
type = mxmlElementGetAttr(node, "type");
if (type == NULL)
type = mxmlGetElement(node);
if (type == NULL)
type = "text";
.PP
if (!strcmp(type, "integer"))
return (MXML_TYPE_INTEGER);
else if (!strcmp(type, "opaque"))
return (MXML_TYPE_OPAQUE);
else if (!strcmp(type, "real"))
return (MXML_TYPE_REAL);
else
return (MXML_TYPE_TEXT);
}
\fB`\fR
.SS mxmlOptionsSetTypeValue
Set the type to use for all child/value nodes.
.PP
.nf
void mxmlOptionsSetTypeValue (
mxml_options_t *options,
mxml_type_t type
);
.fi
.PP
This functions sets a constant node type to use for all child/value nodes.
.SS mxmlOptionsSetWhitespaceCallback
Set the whitespace callback.
.PP
.nf
void mxmlOptionsSetWhitespaceCallback (
mxml_options_t *options,
mxml_ws_cb_t cb,
void *cbdata
);
.fi
.PP
This function sets the whitespace callback that is used when saving XML data.
The callback function \fBcb\fR specifies a function that returns a whitespace
string or \fBNULL\fR before and after each element. The function receives the
callback data pointer \fBcbdata\fR, the \fBmxml_node_t\fR pointer, and a "when"
value indicating where the whitespace is being added, for example:
.PP
\fB`\fRc
const char \fImy_whitespace_cb(void \fRcbdata, mxml_node_t *node, mxml_ws_t when)
{
if (when == MXML_WS_BEFORE_OPEN || when == MXML_WS_AFTER_CLOSE)
return ("n");
else
return (NULL);
}
\fB`\fR
.SS mxmlOptionsSetWrapMargin
Set the wrap margin when saving XML data.
.PP
.nf
void mxmlOptionsSetWrapMargin (
mxml_options_t *options,
int column
);
.fi
.PP
This function sets the wrap margin used when saving XML data. Wrapping is
disabled when \fBcolumn\fR is \fB0\fR.
.SS mxmlRelease
Release a node.
.PP
.nf
int mxmlRelease (
mxml_node_t *node
);
.fi
.PP
When the reference count reaches zero, the node (and any children)
is deleted via \fImxmlDelete\fR.
.SS mxmlRemove
Remove a node from its parent.
.PP
.nf
void mxmlRemove (
mxml_node_t *node
);
.fi
.PP
This function does not free memory used by the node - use \fImxmlDelete\fR
for that. This function does nothing if the node has no parent.
.SS mxmlRetain
Retain a node.
.PP
.nf
int mxmlRetain (
mxml_node_t *node
);
.fi
.SS mxmlSaveAllocString
Save an XML tree to an allocated string.
.PP
.nf
char * mxmlSaveAllocString (
mxml_node_t *node,
mxml_options_t *options
);
.fi
.PP
This function saves the XML tree \fBnode\fR to an allocated string. The string
should be freed using \fBfree\fR (or the string free callback set using
\fImxmlSetStringCallbacks\fR) when you are done with it.
.PP
\fBNULL\fR is returned if the node would produce an empty string or if the string
cannot be allocated.
.PP
Save options are provides via the \fBoptions\fR argument. If \fBNULL\fR, the XML
output will be wrapped at column 72 with no additional whitespace. Use the
\fImxmlOptionsNew\fR function to create options for saving XML data.
.SS mxmlSaveFd
Save an XML tree to a file descriptor.
.PP
.nf
bool mxmlSaveFd (
mxml_node_t *node,
mxml_options_t *options,
int fd
);
.fi
.PP
This function saves the XML tree \fBnode\fR to a file descriptor.
.PP
Save options are provides via the \fBoptions\fR argument. If \fBNULL\fR, the XML
output will be wrapped at column 72 with no additional whitespace. Use the
\fImxmlOptionsNew\fR function to create options for saving XML data.
.SS mxmlSaveFile
Save an XML tree to a file.
.PP
.nf
bool mxmlSaveFile (
mxml_node_t *node,
mxml_options_t *options,
FILE *fp
);
.fi
.PP
This function saves the XML tree \fBnode\fR to a stdio \fBFILE\fR.
.PP
Save options are provides via the \fBoptions\fR argument. If \fBNULL\fR, the XML
output will be wrapped at column 72 with no additional whitespace. Use the
\fImxmlOptionsNew\fR function to create options for saving XML data.
.SS mxmlSaveFilename
Save an XML tree to a file.
.PP
.nf
bool mxmlSaveFilename (
mxml_node_t *node,
mxml_options_t *options,
const char *filename
);
.fi
.PP
This function saves the XML tree \fBnode\fR to a named file.
.PP
Save options are provides via the \fBoptions\fR argument. If \fBNULL\fR, the XML
output will be wrapped at column 72 with no additional whitespace. Use the
\fImxmlOptionsNew\fR function to create options for saving XML data.
.SS mxmlSaveIO
Save an XML tree using a callback.
.PP
.nf
bool mxmlSaveIO (
mxml_node_t *node,
mxml_options_t *options,
mxml_io_cb_t io_cb,
void *io_cbdata
);
.fi
.PP
This function saves the XML tree \fBnode\fR using a write callback function
\fBio_cb\fR. The write callback is called with the callback data pointer
\fBio_cbdata\fR, a buffer pointer, and the number of bytes to write, for
example:
.PP
\fB`\fRc
size_t my_io_cb(void \fIcbdata, const void \fRbuffer, size_t bytes)
{
... write/copy bytes from buffer to the output ...
... return the number of bytes written/copied or 0 on error ...
}
.nf
Save options are provides via the `options` argument. If `NULL`, the XML
output will be wrapped at column 72 with no additional whitespace. Use the
@link mxmlOptionsNew@ function to create options for saving XML data.
.fi
, "real"))
return (MXML_TYPE_REAL);
else
return (MXML_TYPE_TEXT);
}
\fB`\fR
.SS mxmlSaveString
Save an XML node tree to a string.
.PP
.nf
size_t mxmlSaveString (
mxml_node_t *node,
mxml_options_t *options,
char *buffer,
size_t bufsize
);
.fi
.PP
This function saves the XML tree \fBnode\fR to a fixed-size string buffer.
.PP
Save options are provides via the \fBoptions\fR argument. If \fBNULL\fR, the XML
output will be wrapped at column 72 with no additional whitespace. Use the
\fImxmlOptionsNew\fR function to create options for saving XML data.
.SS mxmlSetCDATA
Set the data for a CDATA node.
.PP
.nf
bool mxmlSetCDATA (
mxml_node_t *node,
const char *data
);
.fi
.PP
This function sets the value string for a CDATA node. The node is not
changed if it (or its first child) is not a CDATA node.
.SS mxmlSetCDATAf
Set the data for a CDATA to a formatted string.
.PP
.nf
bool mxmlSetCDATAf (
mxml_node_t *node,
const char *format,
...
);
.fi
.PP
This function sets the formatted string value of a CDATA node. The node is
not changed if it (or its first child) is not a CDATA node.
.SS mxmlSetComment
Set a comment to a literal string.
.PP
.nf
bool mxmlSetComment (
mxml_node_t *node,
const char *comment
);
.fi
.PP
This function sets the string value of a comment node.
.SS mxmlSetCommentf
Set a comment to a formatted string.
.PP
.nf
bool mxmlSetCommentf (
mxml_node_t *node,
const char *format,
...
);
.fi
.PP
This function sets the formatted string value of a comment node.
.SS mxmlSetCustom
Set the data and destructor of a custom data node.
.PP
.nf
bool mxmlSetCustom (
mxml_node_t *node,
void *data,
mxml_custfree_cb_t free_cb,
void *free_cbdata
);
.fi
.PP
This function sets the data pointer \fBdata\fR and destructor callback
\fBdestroy_cb\fR of a custom data node. The node is not changed if it (or its
first child) is not a custom node.
.SS mxmlSetDeclaration
Set a declaration to a literal string.
.PP
.nf
bool mxmlSetDeclaration (
mxml_node_t *node,
const char *declaration
);
.fi
.PP
This function sets the string value of a declaration node.
.SS mxmlSetDeclarationf
Set a declaration to a formatted string.
.PP
.nf
bool mxmlSetDeclarationf (
mxml_node_t *node,
const char *format,
...
);
.fi
.PP
This function sets the formatted string value of a declaration node.
.SS mxmlSetDirective
Set a processing instruction to a literal string.
.PP
.nf
bool mxmlSetDirective (
mxml_node_t *node,
const char *directive
);
.fi
.PP
This function sets the string value of a processing instruction node.
.SS mxmlSetDirectivef
Set a processing instruction to a formatted string.
.PP
.nf
bool mxmlSetDirectivef (
mxml_node_t *node,
const char *format,
...
);
.fi
.PP
This function sets the formatted string value of a processing instruction
node.
.SS mxmlSetElement
Set the name of an element node.
.PP
.nf
bool mxmlSetElement (
mxml_node_t *node,
const char *name
);
.fi
.PP
This function sets the name of an element node. The node is not changed if
it is not an element node.
.SS mxmlSetInteger
Set the value of an integer node.
.PP
.nf
bool mxmlSetInteger (
mxml_node_t *node,
long integer
);
.fi
.PP
This function sets the value of an integer node. The node is not changed if
it (or its first child) is not an integer node.
.SS mxmlSetOpaque
Set the value of an opaque node.
.PP
.nf
bool mxmlSetOpaque (
mxml_node_t *node,
const char *opaque
);
.fi
.PP
This function sets the string value of an opaque node. The node is not
changed if it (or its first child) is not an opaque node.
.SS mxmlSetOpaquef
Set the value of an opaque string node to a formatted string.
.PP
.nf
bool mxmlSetOpaquef (
mxml_node_t *node,
const char *format,
...
);
.fi
.PP
This function sets the formatted string value of an opaque node. The node is
not changed if it (or its first child) is not an opaque node.
.SS mxmlSetReal
Set the value of a real value node.
.PP
.nf
bool mxmlSetReal (
mxml_node_t *node,
double real
);
.fi
.PP
This function sets the value of a real value node. The node is not changed
if it (or its first child) is not a real value node.
.SS mxmlSetText
Set the value of a text node.
.PP
.nf
bool mxmlSetText (
mxml_node_t *node,
bool whitespace,
const char *string
);
.fi
.PP
This function sets the string and whitespace values of a text node. The node
is not changed if it (or its first child) is not a text node.
.SS mxmlSetTextf
Set the value of a text node to a formatted string.
.PP
.nf
bool mxmlSetTextf (
mxml_node_t *node,
bool whitespace,
const char *format,
...
);
.fi
.PP
This function sets the formatted string and whitespace values of a text node.
The node is not changed if it (or its first child) is not a text node.
.SS mxmlSetUserData
Set the user data pointer for a node.
.PP
.nf
bool mxmlSetUserData (
mxml_node_t *node,
void *data
);
.fi
.SS mxmlWalkNext
Walk to the next logical node in the tree.
.PP
.nf
mxml_node_t * mxmlWalkNext (
mxml_node_t *node,
mxml_node_t *top,
mxml_descend_t descend
);
.fi
.PP
This function walks to the next logical node in the tree. The \fBdescend\fR
argument controls whether the first child is considered to be the next node.
The \fBtop\fR argument constrains the walk to that node's children.
.SS mxmlWalkPrev
Walk to the previous logical node in the tree.
.PP
.nf
mxml_node_t * mxmlWalkPrev (
mxml_node_t *node,
mxml_node_t *top,
mxml_descend_t descend
);
.fi
.PP
This function walks to the previous logical node in the tree. The \fBdescend\fR
argument controls whether the first child is considered to be the next node.
The \fBtop\fR argument constrains the walk to that node's children.
.SH TYPES
.SS mxml_add_t
\fImxmlAdd\fR add values
.PP
.nf
typedef enum mxml_add_e mxml_add_t;
.fi
.SS mxml_custfree_cb_t
Custom data destructor
.PP
.nf
typedef void(*)(void *cbdata void *custdata) mxml_custfree_cb_t;
.fi
.SS mxml_custload_cb_t
Custom data load callback function
.PP
.nf
typedef bool(*)(void *cbdata mxml_node_t *node const char *s) mxml_custload_cb_t;
.fi
.SS mxml_custsave_cb_t
Custom data save callback function
.PP
.nf
typedef char *(*)(void *cbdata mxml_node_t *node) mxml_custsave_cb_t;
.fi
.SS mxml_descend_t
\fImxmlFindElement\fR, \fImxmlWalkNext\fR, and \fImxmlWalkPrev\fR descend values
.PP
.nf
typedef enum mxml_descend_e mxml_descend_t;
.fi
.SS mxml_entity_cb_t
Entity callback function
.PP
.nf
typedef int(*)(void *cbdata const char *name) mxml_entity_cb_t;
.fi
.SS mxml_error_cb_t
Error callback function
.PP
.nf
typedef void(*)(void *cbdata const char *message) mxml_error_cb_t;
.fi
.SS mxml_index_t
An XML node index
.PP
.nf
typedef struct _mxml_index_s mxml_index_t;
.fi
.SS mxml_io_cb_t
Read/write callback function
.PP
.nf
typedef size_t(*)(void *cbdata void *buffer size_t bytes) mxml_io_cb_t;
.fi
.SS mxml_node_t
An XML node
.PP
.nf
typedef struct _mxml_node_s mxml_node_t;
.fi
.SS mxml_options_t
XML options
.PP
.nf
typedef struct _mxml_options_s mxml_options_t;
.fi
.SS mxml_sax_cb_t
SAX callback function
.PP
.nf
typedef bool(*)(void *cbdata mxml_node_t *node mxml_sax_event_t event) mxml_sax_cb_t;
.fi
.SS mxml_sax_event_t
SAX event type.
.PP
.nf
typedef enum mxml_sax_event_e mxml_sax_event_t;
.fi
.SS mxml_strcopy_cb_t
String copy/allocation callback
.PP
.nf
typedef char *(*)(void *cbdata const char *s) mxml_strcopy_cb_t;
.fi
.SS mxml_strfree_cb_t
String free callback
.PP
.nf
typedef void(*)(void *cbdata char *s) mxml_strfree_cb_t;
.fi
.SS mxml_type_cb_t
Type callback function
.PP
.nf
typedef mxml_type_t(*)(void *cbdata mxml_node_t *node) mxml_type_cb_t;
.fi
.SS mxml_type_t
The XML node type.
.PP
.nf
typedef enum mxml_type_e mxml_type_t;
.fi
.SS mxml_ws_cb_t
Whitespace callback function
.PP
.nf
typedef const char *(*)(void *cbdata mxml_node_t *node mxml_ws_t when) mxml_ws_cb_t;
.fi
.SS mxml_ws_t
Whitespace periods
.PP
.nf
typedef enum mxml_ws_e mxml_ws_t;
.fi
.SH SEE ALSO
Mini-XML Programmers Manual, https://www.msweet.org/mxml
.SH COPYRIGHT
Copyright \[co] 2003-2021 by Michael R Sweet.
|