diff --git a/doc/basics.html b/doc/basics.html index df65b45..6ce6b98 100644 --- a/doc/basics.html +++ b/doc/basics.html @@ -36,22 +36,22 @@ for your installation:
Every piece of information in an XML file (elements, text, numbers) is stored in memory in "nodes". Nodes are defined by the mxml_node_t +href='#mxml_node_t'>mxml_node_t structure. The type member +href='#mxml_type_t'>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.
+href='#mxml_value_t'>value union.New nodes can be created using the mxmlNewElement(), +href='#mxmlNewElement'>mxmlNewElement(), mxmlNewInteger(), +href='#mxmlNewInteger'>mxmlNewInteger(), mxmlNewOpaque(), -mxmlNewReal(), +href='#mxmlNewOpaque'>mxmlNewOpaque(), +mxmlNewReal(), and mxmlNewText() +href='#mxmlNewText'>mxmlNewText() functions. Only elements can have child nodes, and the top node must be an element, usually "?xml".
@@ -98,7 +98,7 @@ like the following in memory: to the first child node.Once you are done with the XML data, use the mxmlDelete() +href='#mxmlDelete'>mxmlDelete() function to recursively free the memory that is used for a particular node or the entire tree:
@@ -109,15 +109,15 @@ particular node or the entire tree:You load an XML file using the mxmlLoadFile() +href='#mxmlLoadFile'>mxmlLoadFile() function:
FILE *fp; - mxml_node_t *tree; + mxml_node_t *tree; fp = fopen("filename.xml", "r"); - tree = mxmlLoadFile(NULL, fp, MXML_NO_CALLBACK); + tree = mxmlLoadFile(NULL, fp, MXML_NO_CALLBACK); fclose(fp);@@ -131,15 +131,15 @@ attribute values to determine the proper value type to return. The default value type is MXML_TEXT if no callback is used.
Similarly, you save an XML file using the mxmlSaveFile() +href='#mxmlSaveFile'>mxmlSaveFile() function:
FILE *fp; - mxml_node_t *tree; + mxml_node_t *tree; fp = fopen("filename.xml", "w"); - mxmlSaveFile(tree, fp, MXML_NO_CALLBACK); + mxmlSaveFile(tree, fp, MXML_NO_CALLBACK); fclose(fp);@@ -154,49 +154,49 @@ whitespace should be added and the string to insert (spaces, tabs, carriage returns, and newlines) otherwise.
The mxmlLoadString(), +href='#mxmlLoadString'>mxmlLoadString(), mxmlSaveAllocString(), +href='#mxmlSaveAllocString'>mxmlSaveAllocString(), and mxmlSaveString() +href='#mxmlSaveString'>mxmlSaveString() functions load XML node trees from and save XML node trees to strings:
char buffer[8192]; char *ptr; - mxml_node_t *tree; + mxml_node_t *tree; ... - tree = mxmlLoadString(NULL, buffer, MXML_NO_CALLBACK); + tree = mxmlLoadString(NULL, buffer, MXML_NO_CALLBACK); ... - mxmlSaveString(tree, buffer, sizeof(buffer), MXML_NO_CALLBACK); + mxmlSaveString(tree, buffer, sizeof(buffer), MXML_NO_CALLBACK); ... - ptr = mxmlSaveAllocString(tree, MXML_NO_CALLBACK); + ptr = mxmlSaveAllocString(tree, MXML_NO_CALLBACK);
The mxmlWalkPrev() +href='#mxmlWalkPrev'>mxmlWalkPrev() and mxmlWalkNext()functions +href='#mxmlWalkNext'>mxmlWalkNext()functions can be used to iterate through the XML node tree:
- mxml_node_t *node = mxmlWalkPrev(current, tree, MXML_DESCEND); + mxml_node_t *node = mxmlWalkPrev(current, tree, MXML_DESCEND); - mxml_node_t *node = mxmlWalkNext(current, tree, MXML_DESCEND); + mxml_node_t *node = mxmlWalkNext(current, tree, MXML_DESCEND);
In addition, you can find a named element/node using the mxmlFindElement() +href='#mxmlFindElement'>mxmlFindElement() function:
- mxml_node_t *node = mxmlFindElement(tree, tree, "name", "attr", + mxml_node_t *node = mxmlFindElement(tree, tree, "name", "attr", "value", MXML_DESCEND);@@ -206,30 +206,30 @@ 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); /* 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); /* Find the first "a" element with "href" to a URL */ - node = mxmlFindElement(tree, tree, "a", "href", + 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); + 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); + node = mxmlFindElement(tree, tree, NULL, "src", "foo.jpg", MXML_DESCEND);
You can also iterate with the same function:
- mxml_node_t *node; + mxml_node_t *node; - for (node = mxmlFindElement(tree, tree, "name", NULL, NULL, MXML_DESCEND); + for (node = mxmlFindElement(tree, tree, "name", NULL, NULL, MXML_DESCEND); node != NULL; - node = mxmlFindElement(node, tree, "name", NULL, NULL, MXML_DESCEND)) + node = mxmlFindElement(node, tree, "name", NULL, NULL, MXML_DESCEND)) { ... do something ... } diff --git a/doc/mxml.html b/doc/mxml.html index b57f856..d9dce2f 100644 --- a/doc/mxml.html +++ b/doc/mxml.html @@ -23,7 +23,7 @@ PRE { font-family: monospace } Michael Sweet
Copyright 2003-2004
-
+
Table of Contents
Introduction @@ -101,9 +101,16 @@ Copyright 2003-2004
This programmers manual describes Mini-XML version 2.0, a small XML parsing library that you can use to read and write XML and XML-like @@ -307,7 +320,7 @@ File and directory names.
This chapter describes how to build, install, and package Mini-XML on @@ -370,7 +383,7 @@ epm(1) program to create software packages in a variety of formats.
The native packages will be in the local OS's native format: RPM for Red Hat Linux, DPKG for Debian Linux, PKG for Solaris, and so forth. Use the corresponding commands to install the native packages.
-This chapter describes how to write programs that use Mini-XML to access data in an XML file.
@@ -592,7 +605,7 @@ mxmlSaveString() functions load XML node trees from and save the order would be reversed, ending at "?xml".This chapter shows additional ways to use the Mini-XML library in @@ -602,7 +615,7 @@ mxmlSaveString() functions load XML node trees from and save
This chapter describes how to use the mxmldoc(1) utility
that comes with Mini-XML to automatically generate documentation for
@@ -957,7 +970,7 @@ align="bottom"> Listing 4-1, XML Schema File "mxmldoc.xsd" (con't)<
-
+
A - GNU Library General Public
License
Version 2, June 1991 @@ -1333,11 +1346,22 @@ align="bottom"> Listing 4-1, XML Schema File "mxmldoc.xsd" (con't)< SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
-Nothing.
+ +Add a callback to convert entities to Unicode.
++void +mxmlEntityAddCallback( + int (*cb)(const char *name)); ++
Name | Description |
---|---|
(*cb)(const char *name) | Callback function to + add |
Nothing.
+Character value or -1 on error
+ +Remove a callback.
++void +mxmlEntityRemoveCallback( + int (*cb)(const char *name)); ++
Name | Description |
---|---|
(*cb)(const char *name) | Callback function to + remove |
Nothing.
+Element node or NULL
+ +Delete an index.
++void +mxmlIndexDelete( + mxml_index_t * ind); ++
Name | Description |
---|---|
ind | Index to delete |
Nothing.
+ + +Return the next node in the index. Nodes are returned in the sorted + order of the index.
++mxml_node_t * +mxmlIndexEnum( + mxml_index_t * ind); ++
Name | Description |
---|---|
ind | Index to enumerate |
Next node or NULL if there is none
+ + +Find the next matching node. You should call mxmlIndexReset() prior + to using this function for the first time with a particular set of + "element" and "value" strings. Passing NULL for both "element" and + "value" is equivalent to calling mxmlIndexEnum().
++mxml_node_t * +mxmlIndexFind( + mxml_index_t * ind, + const char * element, + const char * value); ++
Name | Description |
---|---|
ind | Index to search |
element | Element name to find, if any |
value | Attribute value, if any |
Node or NULL if none found
+ + +Create a new index. The index will contain all nodes that contain the + named element and/or attribute. If both "element" and "attr" are NULL, + 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 "attr" argument is not NULL.
++mxml_index_t * +mxmlIndexNew( + mxml_node_t * node, + const char * element, + const char * attr); ++
Name | Description |
---|---|
node | XML node tree |
element | Element to index or NULL for all |
attr | Attribute to index or NULL for none |
New index
+ + +Reset the enumeration/find pointer in the index and return the first + node in the index. This function should be called prior to using + mxmlIndexEnum() or mxmlIndexFind() for the first time.
++mxml_node_t * +mxmlIndexReset( + mxml_index_t * ind); ++
Name | Description |
---|---|
ind | Index to reset |
First node or NULL if there is none
+An XML node index.
++struct mxml_index_s +{ + int alloc_nodes; + char * attr; + int cur_node; + mxml_node_t ** nodes; + int num_nodes; +}; ++
Name | Description |
---|---|
alloc_nodes | Allocated nodes in index |
attr | Attribute used for indexing or NULL |
cur_node | Current node |
nodes | Node array |
num_nodes | Number of nodes in index |
An XML node index.
++typedef struct mxml_index_s mxml_index_t; ++
+static int num_callbacks = 1; +