From d54a88db43f3e5c987b2b355c86275471efcafbf Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Wed, 20 Mar 2024 11:32:06 -0400 Subject: [PATCH] Update README.md examples. --- README.md | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 720932e..b3895a1 100644 --- a/README.md +++ b/README.md @@ -87,26 +87,24 @@ Mini-XML provides a single header file which you include: #include -Nodes (elements, comments, processing directives, integers, opaque strings, real -numbers, and text strings) are represented by `mxml_node_t` objects. New nodes -can be created using the mxmlNewComment, mxmlNewCustom, mxmlNewDeclaration, -mxmlNewDirective, mxmlNewElement, mxmlNewInteger, mxmlNewOpaque, mxmlNewReal, -and mxmlNewText functions. The top node must be the "?xml ...?" processing -instruction. +Nodes (elements, comments, declarations, integers, opaque strings, processing +instructions, real numbers, and text strings) are represented by `mxml_node_t` +pointers. New nodes can be created using the mxmlNewXxx functions. The top +node must be the `` processing instruction. You load an XML file using the mxmlLoadFilename function: mxml_node_t *tree; - tree = mxmlLoadFilename(NULL, "filename.xml", - /*load_cb*/NULL, /*load_cbdata*/NULL); + tree = mxmlLoadFilename(/*top*/NULL, /*options*/NULL, + "example.xml"); Similarly, you save an XML file using the mxmlSaveFilename function: mxml_node_t *tree; - mxmlSaveFilename(tree, "filename.xml", - /*load_cb*/NULL, /*load_cbdata*/NULL); + mxmlSaveFilename(tree, /*options*/NULL, + "filename.xml"); There are variations of these functions for loading from or saving to file descriptors, `FILE` pointers, strings, and IO callbacks. @@ -114,38 +112,37 @@ descriptors, `FILE` pointers, strings, and IO callbacks. You can find a named element/node using the mxmlFindElement function: mxml_node_t *node = mxmlFindElement(tree, tree, "name", "attr", - "value", MXML_DESCEND); + "value", MXML_DESCEND_ALL); The `name`, `attr`, and `value` arguments can be passed as `NULL` to act as wildcards, e.g.: /* Find the first "a" element */ - node = mxmlFindElement(tree, tree, "a", NULL, NULL, MXML_DESCEND); + node = mxmlFindElement(tree, tree, "a", NULL, NULL, MXML_DESCEND_ALL); /* Find the first "a" element with "href" attribute */ - node = mxmlFindElement(tree, tree, "a", "href", NULL, MXML_DESCEND); + node = mxmlFindElement(tree, tree, "a", "href", NULL, MXML_DESCEND_ALL); /* Find the first "a" element with "href" to a URL */ node = mxmlFindElement(tree, tree, "a", "href", - "http://www.minixml.org/", - MXML_DESCEND); + "https://www.msweet.org/mxml", MXML_DESCEND_ALL); /* Find the first element with a "src" attribute*/ - node = mxmlFindElement(tree, tree, NULL, "src", NULL, MXML_DESCEND); + node = mxmlFindElement(tree, tree, NULL, "src", NULL, MXML_DESCEND_ALL); /* Find the first element with a "src" = "foo.jpg" */ node = mxmlFindElement(tree, tree, NULL, "src", "foo.jpg", - MXML_DESCEND); + MXML_DESCEND_ALL); You can also iterate with the same function: mxml_node_t *node; for (node = mxmlFindElement(tree, tree, "name", NULL, NULL, - MXML_DESCEND); + MXML_DESCEND_ALL); node != NULL; node = mxmlFindElement(node, tree, "name", NULL, NULL, - MXML_DESCEND)) + MXML_DESCEND_ALL)) { ... do something ... } @@ -166,7 +163,7 @@ retrieve the corresponding value from a node: double realvalue = mxmlGetReal(node); - int whitespacevalue; + bool whitespacevalue; const char *textvalue = mxmlGetText(node, &whitespacevalue); Finally, once you are done with the XML data, use the mxmlDelete function to