📄 mxml.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><HTML><HEAD><TITLE>Mini-XML Programmers Manual, Version 2.5</TITLE><META NAME="author" CONTENT="Michael R. Sweet"><META NAME="copyright" CONTENT="Copyright 2003-2008"><META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso-iso-8859-1"><STYLE TYPE="text/css"><!--BODY { font-family: sans-serif }H1 { font-family: sans-serif }H2 { font-family: sans-serif }H3 { font-family: sans-serif }H4 { font-family: sans-serif }H5 { font-family: sans-serif }H6 { font-family: sans-serif }SUB { font-size: smaller }SUP { font-size: smaller }PRE { font-family: monospace }A { text-decoration: none }--></STYLE></HEAD><BODY><H1 ALIGN="CENTER"><A NAME="CONTENTS">Table of Contents</A></H1><BR><BR><B><A HREF="#INTRO">Introduction</A></B><UL><LI><A HREF="#1_1">Organization of This Document</A></LI><LI><A HREF="#1_2">Notation Conventions</A></LI><LI><A HREF="#1_3">Abbreviations</A></LI><LI><A HREF="#1_4">Other References</A></LI><LI><A HREF="#1_5">Legal Stuff</A></LI></UL><B><A HREF="#INSTALL">Building, Installing, and Packaging Mini-XML</A></B><UL><LI><A HREF="#2_1">Compiling Mini-XML</A><UL><LI><A HREF="#2_1_1">Compiling with Visual C++</A></LI><LI><A HREF="#2_1_2">Compiling with Command-Line Tools</A></LI></UL></LI><LI><A HREF="#2_2">Installing Mini-XML</A></LI><LI><A HREF="#2_3">Creating Mini-XML Packages</A></LI></UL><B><A HREF="#BASICS">Getting Started with Mini-XML</A></B><UL><LI><A HREF="#3_1">The Basics</A></LI><LI><A HREF="#3_2">Nodes</A></LI><LI><A HREF="#3_3">Creating XML Documents</A></LI><LI><A HREF="#3_4">Loading XML</A></LI><LI><A HREF="#3_5">Saving XML</A><UL><LI><A HREF="#3_5_1">Controlling Line Wrapping</A></LI></UL></LI><LI><A HREF="#3_6">Finding and Iterating Nodes</A></LI></UL><B><A HREF="#ADVANCED">More Mini-XML Programming Techniques</A></B><UL><LI><A HREF="#LOAD_CALLBACKS">Load Callbacks</A></LI><LI><A HREF="#SAVE_CALLBACKS">Save Callbacks</A></LI><LI><A HREF="#4_3">Custom Data Types</A></LI><LI><A HREF="#4_4">Changing Node Values</A></LI><LI><A HREF="#4_5">Formatted Text</A></LI><LI><A HREF="#4_6">Indexing</A></LI><LI><A HREF="#4_7">SAX (Stream) Loading of Documents</A></LI></UL><B><A HREF="#MXMLDOC">Using the mxmldoc Utility</A></B><UL><LI><A HREF="#5_1">The Basics</A></LI><LI><A HREF="#5_2">Commenting Your Code</A></LI><LI><A HREF="#5_3">Titles, Sections, and Introductions</A></LI></UL><B><A HREF="#LICENSE">Mini-XML License</A></B><BR><BR><B><A HREF="#RELNOTES">Release Notes</A></B><UL></UL><B><A HREF="#REFERENCE">Library Reference</A></B><UL><LI><A HREF="#8_1">Contents</A></LI><LI><A HREF="#FUNCTIONS">Functions</A><UL><LI><A HREF="#mxmlAdd">mxmlAdd</A></LI><LI><A HREF="#mxmlDelete">mxmlDelete</A></LI><LI><A HREF="#8_2_3">mxmlElementDeleteAttr</A></LI><LI><A HREF="#mxmlElementGetAttr">mxmlElementGetAttr</A></LI><LI><A HREF="#mxmlElementSetAttr">mxmlElementSetAttr</A></LI><LI><A HREF="#8_2_6">mxmlElementSetAttrf</A></LI><LI><A HREF="#mxmlEntityAddCallback">mxmlEntityAddCallback</A></LI><LI><A HREF="#mxmlEntityGetName">mxmlEntityGetName</A></LI><LI><A HREF="#mxmlEntityGetValue">mxmlEntityGetValue</A></LI><LI><A HREF="#mxmlEntityRemoveCallback">mxmlEntityRemoveCallback</A></LI><LI><A HREF="#mxmlFindElement">mxmlFindElement</A></LI><LI><A HREF="#mxmlIndexDelete">mxmlIndexDelete</A></LI><LI><A HREF="#mxmlIndexEnum">mxmlIndexEnum</A></LI><LI><A HREF="#mxmlIndexFind">mxmlIndexFind</A></LI><LI><A HREF="#mxmlIndexNew">mxmlIndexNew</A></LI><LI><A HREF="#mxmlIndexReset">mxmlIndexReset</A></LI><LI><A HREF="#mxmlLoadFd">mxmlLoadFd</A></LI><LI><A HREF="#mxmlLoadFile">mxmlLoadFile</A></LI><LI><A HREF="#mxmlLoadString">mxmlLoadString</A></LI><LI><A HREF="#8_2_20">mxmlNewCDATA</A></LI><LI><A HREF="#8_2_21">mxmlNewCustom</A></LI><LI><A HREF="#mxmlNewElement">mxmlNewElement</A></LI><LI><A HREF="#mxmlNewInteger">mxmlNewInteger</A></LI><LI><A HREF="#mxmlNewOpaque">mxmlNewOpaque</A></LI><LI><A HREF="#mxmlNewReal">mxmlNewReal</A></LI><LI><A HREF="#mxmlNewText">mxmlNewText</A></LI><LI><A HREF="#mxmlNewTextf">mxmlNewTextf</A></LI><LI><A HREF="#8_2_28">mxmlNewXML</A></LI><LI><A HREF="#8_2_29">mxmlRelease</A></LI><LI><A HREF="#mxmlRemove">mxmlRemove</A></LI><LI><A HREF="#8_2_31">mxmlRetain</A></LI><LI><A HREF="#8_2_32">mxmlSAXLoadFd</A></LI><LI><A HREF="#8_2_33">mxmlSAXLoadFile</A></LI><LI><A HREF="#8_2_34">mxmlSAXLoadString</A></LI><LI><A HREF="#mxmlSaveAllocString">mxmlSaveAllocString</A></LI><LI><A HREF="#mxmlSaveFd">mxmlSaveFd</A></LI><LI><A HREF="#mxmlSaveFile">mxmlSaveFile</A></LI><LI><A HREF="#mxmlSaveString">mxmlSaveString</A></LI><LI><A HREF="#8_2_39">mxmlSetCDATA</A></LI><LI><A HREF="#8_2_40">mxmlSetCustom</A></LI><LI><A HREF="#mxmlSetCustomHandlers">mxmlSetCustomHandlers</A></LI><LI><A HREF="#mxmlSetElement">mxmlSetElement</A></LI><LI><A HREF="#mxmlSetErrorCallback">mxmlSetErrorCallback</A></LI><LI><A HREF="#mxmlSetInteger">mxmlSetInteger</A></LI><LI><A HREF="#mxmlSetOpaque">mxmlSetOpaque</A></LI><LI><A HREF="#mxmlSetReal">mxmlSetReal</A></LI><LI><A HREF="#mxmlSetText">mxmlSetText</A></LI><LI><A HREF="#mxmlSetTextf">mxmlSetTextf</A></LI><LI><A HREF="#8_2_49">mxmlSetWrapMargin</A></LI><LI><A HREF="#mxmlWalkNext">mxmlWalkNext</A></LI><LI><A HREF="#mxmlWalkPrev">mxmlWalkPrev</A></LI></UL></LI><LI><A HREF="#TYPES">Data Types</A><UL><LI><A HREF="#mxml_attr_t">mxml_attr_t</A></LI><LI><A HREF="#mxml_custom_destroy_cb_t">mxml_custom_destroy_cb_t</A></LI><LI><A HREF="#mxml_custom_load_cb_t">mxml_custom_load_cb_t</A></LI><LI><A HREF="#mxml_custom_save_cb_t">mxml_custom_save_cb_t</A></LI><LI><A HREF="#8_3_5">mxml_custom_t</A></LI><LI><A HREF="#mxml_element_t">mxml_element_t</A></LI><LI><A HREF="#mxml_error_cb_t">mxml_error_cb_t</A></LI><LI><A HREF="#mxml_index_t">mxml_index_t</A></LI><LI><A HREF="#mxml_load_cb_t">mxml_load_cb_t</A></LI><LI><A HREF="#mxml_node_t">mxml_node_t</A></LI><LI><A HREF="#mxml_save_cb_t">mxml_save_cb_t</A></LI><LI><A HREF="#mxml_sax_cb_t">mxml_sax_cb_t</A></LI><LI><A HREF="#mxml_sax_event_t">mxml_sax_event_t</A></LI><LI><A HREF="#mxml_text_t">mxml_text_t</A></LI><LI><A HREF="#mxml_value_t">mxml_value_t</A></LI></UL></LI><LI><A HREF="#STRUCTURES">Structures</A><UL><LI><A HREF="#mxml_attr_s">mxml_attr_s</A></LI><LI><A HREF="#8_4_2">mxml_custom_s</A></LI><LI><A HREF="#mxml_element_s">mxml_element_s</A></LI><LI><A HREF="#mxml_index_s">mxml_index_s</A></LI><LI><A HREF="#mxml_node_s">mxml_node_s</A></LI><LI><A HREF="#mxml_text_s">mxml_text_s</A></LI></UL></LI><LI><A HREF="#UNIONS">Unions</A><UL><LI><A HREF="#mxml_value_u">mxml_value_u</A></LI></UL></LI><LI><A HREF="#ENUMERATIONS">Constants</A><UL><LI><A HREF="#mxml_sax_event_e">mxml_sax_event_e</A></LI><LI><A HREF="#mxml_type_e">mxml_type_e</A></LI></UL></LI></UL><B><A HREF="#SCHEMA">XML Schema</A></B><UL></UL><HR NOSHADE><H1 align="right"><A name="INTRO"><IMG align="right" alt="0" height="100"hspace="10" src="0.gif" width="100"></A>Introduction</H1><P>This programmers manual describes Mini-XML version 2.5, a small XML parsing library that you can use to read and write XML data files in your C and C++ applications.</P><P>Mini-XML was initially developed for the <A href="http://gutenprint.sf.net/">Gutenprint</A> project to replace the rather large and unwieldy <TT>libxml2</TT> library with something substantially smaller and easier-to-use. It all began one morning in June of 2003 when Robert posted the following sentence to the developer's list:</P><BLOCKQUOTE><EM>It's bad enough that we require libxml2, but rolling our own XML parser is a bit more than we can handle.</EM></BLOCKQUOTE><P>I then replied with:</P><BLOCKQUOTE><EM>Given the limited scope of what you use in XML, it should be trivial to code a mini-XML API in a few hundred lines of code.</EM></BLOCKQUOTE><P>I took my own challenge and coded furiously for two days to produced the initial public release of Mini-XML, total lines of code: 696. Robert promptly integrated Mini-XML into Gutenprint and removed libxml2.</P><P>Thanks to lots of feedback and support from various developers, Mini-XML has evolved since then to provide a more complete XML implementation and now stands at a whopping 3,441 lines of code, compared to 103,893 lines of code for libxml2 version 2.6.9.</P><P>Aside from Gutenprint, Mini-XML is used for the following projects/software applications:</P><UL><LI><A href="http://www.cups.org/">Common UNIX Printing System</A></LI><LI><A href="http://www.cups.org/ddk/">CUPS Driver Development Kit</A></LI><LI><A href="http://zynaddsubfx.sourceforge.net">ZynAddSubFX</A></LI></UL><P>Please email me (mxml @ easysw . com) if you would like your project added or removed from this list, or if you have any comments/quotes you would like me to publish about your experiences with Mini-XML.</P><H2><A NAME="1_1">Organization of This Document</A></H2><P>This manual is organized into the following chapters and appendices:</P><UL><LI>Chapter 1, "<A href="#INSTALL">Building, Installing, and Packaging Mini-XML</A>", provides compilation, installation, and packaging instructions for Mini-XML.</LI><LI>Chapter 2, "<A href="#BASICS">Getting Started with Mini-XML</A>", shows how to use the Mini-XML library in your programs.</LI><LI>Chapter 3, "<A href="#ADVANCED">More Mini-XML Programming Techniques</A>", shows additional ways to use the Mini-XML library.</LI><LI>Chapter 4, "<A href="#MXMLDOC">Using the mxmldoc Utility</A>", describes how to use the <TT>mxmldoc(1)</TT> program to generate software documentation.</LI><LI>Appendix A, "<A href="#LICENSE">Mini-XML License</A>", provides the terms and conditions for using and distributing Mini-XML.</LI><LI>Appendix B, "<A href="#RELNOTES">Release Notes</A>", lists the changes in each release of Mini-XML.</LI><LI>Appendix C, "<A href="#REFERENCE">Library Reference</A>", contains a complete reference for Mini-XML, generated by <TT>mxmldoc</TT>.</LI><LI>Appendix D, "<A href="#SCHEMA">XML Schema</A>", shows the XML schema used for the XML files produced by <TT>mxmldoc</TT>.</LI></UL><!-- NEED 10 --><H2><A NAME="1_2">Notation Conventions</A></H2><P>Various font and syntax conventions are used in this guide. Examples and their meanings and uses are explained below:</P><DL><DT><CODE>lpstat</CODE><BR> <CODE>lpstat(1)</CODE></DT><DD>The names of commands; the first mention of a command or function in a chapter is followed by a manual page section number.<BR><BR></DD><DT><VAR>/var</VAR><BR><VAR> /usr/share/cups/data/testprint.ps</VAR></DT><DD>File and directory names.<BR><BR></DD><DT><TT>Request ID is Printer-123</TT></DT><DD>Screen output.<BR><BR></DD><DT><KBD>lp -d printer filename ENTER</KBD></DT><DD>Literal user input; special keys like <KBD>ENTER</KBD> are in ALL CAPS.<BR><BR></DD><DT>12.3</DT><DD>Numbers in the text are written using the period (.) to indicate the decimal point.<BR><BR></DD></DL><!-- NEED 10 --><H2><A NAME="1_3">Abbreviations</A></H2><P>The following abbreviations are used throughout this manual:</P><DL><DT>Gb</DT><DD>Gigabytes, or 1073741824 bytes<BR><BR></DD><DT>kb</DT><DD>Kilobytes, or 1024 bytes<BR><BR></DD><DT>Mb</DT><DD>Megabytes, or 1048576 bytes<BR><BR></DD><DT>UTF-8, UTF-16</DT><DD>Unicode Transformation Format, 8-bit or 16-bit<BR><BR></DD><DT>W3C</DT><DD>World Wide Web Consortium<BR><BR></DD><DT>XML</DT><DD>Extensible Markup Language<BR><BR></DD></DL><!-- NEED 12 --><H2><A NAME="1_4">Other References</A></H2><DL><DT>The Unicode Standard, Version 4.0, Addison-Wesley, ISBN 0-321-18578-1</DT><DD>The definition of the Unicode character set which is used for XML.<BR><BR></DD><DT><A href="http://www.w3.org/TR/2004/REC-xml-20040204/">Extensible Markup Language (XML) 1.0 (Third Edition)</A></DT><DD>The XML specification from the World Wide Web Consortium (W3C)<BR><BR></DD></DL><!-- NEED 6 --><H2><A NAME="1_5">Legal Stuff</A></H2><P>The Mini-XML library is copyright 2003-2008 by Michael Sweet.</P><P>This library is free software; you can redistribute it and/or modify it under the terms of the <A href="#LICENSE">GNU Library General Public License</A> as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.</P><P>This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -