Closed michaelrsweet closed 15 years ago
Original reporter: Michael Sweet
Will put this up on the web site in the future...
"minixml-cn.html":
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head>
<style type="text/css">
.zf {
font-size : small;
background-color : #fffbc0;
border-style : solid;
border-color : #fff949;
border-width : 1px;
color : #0d039c;
}
</style>
<title>Mini-XML ç¨åºåå¼åæå, Version 2.5</title>
<meta name="author" content="Michael R. Sweet">
<meta name="Translator" content="ZhuFeng">
<meta name="copyright" content="Copyright 2003-2008">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><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"> ç®å½</a></h1>
<div class="zf" align="right">ä¸æç¿»è¯ï¼Z.F , mail: zhfjyq@gmail.com ,<a href="http://blog.csdn.net/bluesonic">http://blog.csdn.net/bluesonic</a></div>
<br>
<br><b><a href="#INTRO">åºè¨</a></b>
<ul>
<li><a href="#1_1">æ¬æç»æ </a></li>
<li><a href="#1_2">è¯æ³çº¦å® </a></li>
<li><a href="#1_3">缩ç¥è¯ </a></li>
<li><a href="#1_4">å
¶ä»åè </a></li>
<li><a href="#1_5">æ³å¾ä¿¡æ¯ </a></li>
</ul>
<b><a href="#INSTALL">æ建ï¼å®è£
ï¼ä»¥åæå
Mini-XML </a></b>
<ul>
<li><a href="#2_1">ç¼è¯ Mini-XML</a>
<ul>
<li><a href="#2_1_1">ä½¿ç¨ Visual C++ è¿è¡ç¼è¯</a></li>
<li><a href="#2_1_2"> 使ç¨å½ä»¤è¡å·¥å
·è¿è¡ç¼è¯ </a></li>
</ul>
</li>
<li><a href="#2_2">å®è£
Mini-XML</a></li>
<li><a href="#2_3">å建 Mini-XML å
</a></li>
</ul>
<b><a href="#BASICS">Mini-XML å
¥é¨</a></b>
<ul>
<li><a href="#3_1">åºç¡ç¥è¯</a></li>
<li><a href="#3_2">èç¹</a></li>
<li><a href="#3_3">å建 XML ææ¡£ </a></li>
<li><a href="#3_4">å è½½ XML</a></li>
<li><a href="#3_5">ä¿å XML</a>
<ul>
<li><a href="#3_5_1">æ§å¶èªå¨è¾åºæ¢è¡ </a></li>
</ul>
</li>
<li><a href="#3_6">æç´¢åéåèç¹ </a></li>
</ul>
<b><a href="#ADVANCED">æ´å¤ç Mini-XML ç¼ç¨ææ¯</a></b>
<ul>
<li><a href="#LOAD_CALLBACKS">å è½½åè°å½æ° </a></li>
<li><a href="#SAVE_CALLBACKS">ä¿ååè°å½æ° </a></li>
<li><a href="#4_3">ç¨æ·å®ä¹æ°æ®ç±»å</a></li>
<li><a href="#4_4">æ¹åèç¹çå¼</a></li>
<li><a href="#4_5">æ ¼å¼åææ¬</a></li>
<li><a href="#4_6">ç´¢å¼</a></li>
<li><a href="#4_7">SAX (æµæ¹å¼è§£æ) å è½½ææ¡£</a></li>
</ul>
<b><a href="#MXMLDOC">ä½¿ç¨ mxmldoc å·¥å
·</a></b>
<ul>
<li><a href="#5_1">åºç¡ç¥è¯</a></li>
<li><a href="#5_2">ä¸ºä½ ç代ç æ·»å 注é</a></li>
<li><a href="#5_3">æ é¢ãå段ååç®ä»</a></li>
</ul>
<b><a href="#LICENSE">Mini-XML 许å¯ä¿¡æ¯</a></b>
<br>
<br><b><a href="#RELNOTES">åè¡è¯´æ</a></b>
<ul></ul>
<b><a href="#REFERENCE">åºåèæå</a></b>
<ul>
<li><a href="#8_1">ç®å½</a></li>
<li><a href="#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">ç±»åå®ä¹(typedef)</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">ç»æ(struct)</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">èå(union)</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æ¹æ¡ (ç¨äºèªå¨åææ¡£çæå·¥å
· mxmldoc)</a></b>
<ul></ul>
<hr noshade="noshade">
<h1 align="right"><a name="INTRO"><img alt="0" src="minixml-cn_files/0.gif" align="right" height="100" hspace="10" width="100"></a>åºè¨</h1>
<p>è¿ä»½ç¨åºååèæåæè¿°äº Mini-XML 2.5çæ¬, ä¸ä¸ªå°åç XML 解æåºï¼ä½¿ç¨å®å¯ä»¥ä½¿ä½ çCæè
C++åºç¨ç¨åºæ¹ä¾¿çè¿è¡XMLæ°æ®æ件ç读å
</p>
<p>Mini-XML æåæ¯ä¸ºäº<a href="http://gutenprint.sf.net/">
Gutenprint</a> 项ç®èå¼åï¼ç®çæ¯ä¸ºäºæ¿æ¢æ¢å¤§å笨éç<tt>
libxml2</tt> åºï¼ æ³è¦å®ç°ä¸ä¸ªå°åä¸æäºä½¿ç¨çä¸äºä¸è¥¿. å®å¼å§äº2003å¹´6æçä¸ä¸ªæ©æ¨ï¼å½æ¶ç½ä¼¯ç¹å表äºä¸é¢å å¥è¯å°å¼åè
å表ï¼
</p>
<blockquote><em>"è¿çæ¯ç³ç³ï¼æ们éè¦libxml2,ä½åå¤çæ¥ï¼æ们çXML解æå¨ä»
éè¦æ们å¯ä»¥æä½çä¸å°é¨åã" </em></blockquote>
<p>æåäºä»¥ä¸åå¤:</p>
<blockquote><em>"èèå°ä½ 使ç¨XMLä»
å¨ä¸ä¸ªæéçèå´ä¸ï¼é£ä¹åªä½¿ç¨å ç¾è¡ä»£ç æ¥ç¼åä¸ä¸ªå¾®åXML (mini-XML) APIï¼åºè¯¥æ¯å¾ç®åçã"</em></blockquote>
<p>ææ¥åäºè¿ä¸ªææï¼ç¨äºä¸¤å¤©çæ¶é´è¿è¡ç¯ççç¼ç ï¼å¹¶ä¸å
¬å¼åå¸äºç¬¬ä¸ä¸ªmini-XMLçæ¬ï¼æ»å
±æ¯696è¡ä»£ç ãç¶åï¼ç½ä¼¯ç¹è¿
éæmini-XMLæ´åå° Gutenprint ä¸ï¼å¹¶ä¸ç§»é¤äºlibxml2åº</p>
<p>æè°¢å¾å¤ä¸åçå¼åè
ç»æçåé¦åæ¯æï¼ ä»é£ä»¥åï¼Mini-XMLéæ¸åå±ä¸ºä¸ä¸ªæä¾æ´å¤å®æ´çXMLå®ç°ï¼å½åå·²ç»é«è¾¾3441è¡ä»£ç ï¼ä½å·²ç»å¯ä»¥å103893è¡ä»£ç çlibxml2 2.6.9çæ¬ç¸æ¯è¾äºã
</p>
<div class="zf">è¯è
ï¼ä»
ç¨äºä¸¤å¤©æ¶é´ï¼ä½è
çæ¯å¤§çåï¼æè¾å欢Mini-XMLï¼æä¹ç¨è¿TinyXMLï¼libexpat,libxml2ç解æå¨ï¼ç¸æ¯ä¹ä¸Mini-XMLå®ç°äºä¸ä¸ªé常ç®æ´ä¸åè½éç¨ç解æå¨ï¼å¾éåæçéæ±ï¼DOMå解æå¨ã解æå°åçXMLæ件ï¼ä¸è¿è¡é误æ¢å¤åæ ¡éªï¼ç®åæç¨ï¼ä¸ä½¿ç¨çº¯ANSI-Cå®ç°ï¼æ¹ä¾¿ç§»æ¤å°åµå
¥ç³»ç»ä¸ãè¯ä»·ï¼å¾å¥½å¾å¼ºå¤§ï¼èä¸å¾ç®åãZ.F</div>
<p>é¤äºGutenprint ï¼mini-XMLå½åå·²ç»åºç¨äºä»¥ä¸ç项ç®/åºç¨è½¯ä»¶:</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>
å¦ææ¨å¸æå°æ¨ç项ç®æ·»å å°æ¤å表æè
ä»æ¤å表ä¸å é¤ï¼æè
å¦ææ¨æä»»ä½æè§åæ³æ³ï¼æè
æ³è¦åå¸å
³äºä½¿ç¨mini-XMLçç»éªï¼è¯·ç»æåçµåé®ä»¶ï¼ mxml@easysw.com ï¼
</p>
<h2><a name="1_1">æ¬ææ¡£ç»ç»ç»æ</a></h2>
<p>æ¬æåç±ä»¥ä¸ç« èåéå½ç»æ:</p>
<ul>
<li>第ä¸ç« , "<a href="#INSTALL">æ建ï¼å®è£
ï¼ä»¥åæå
Mini-XML</a>", å
³äºmini-XMLå¨ç¼è¯ãå®è£
以åæå
æ¹é¢ç说æ.</li>
<li>第äºç« , "<a href="#BASICS">Mini-XML å
¥é¨</a>",å¦ä½å¨ä½ çåºç¨ç¨åºä¸ä½¿ç¨mini-XML.
</li>
<li>第ä¸ç« , "<a href="#ADVANCED">æ´å¤ç Mini-XML ç¼ç¨ææ¯</a>å±ç¤ºäºä½¿ç¨mini-XMLåºçæ´å¤çæ¹æ³ã
</li>
<li>第åç« , "<a href="#MXMLDOC">ä½¿ç¨ mxmldoc å·¥å
·</a>",
æè¿°å¦ä½ä½¿ç¨<tt>mxmldoc(1)</tt> ç¨åºæ¥çæææ¡£.</li>
<li>éå½ A, "<a href="#LICENSE">Mini-XML 许å¯ä¿¡æ¯ </a>",使ç¨ååå¸mini-XMLçæ¡æ¬¾åæ¡ä»¶ã</li>
<li>éå½ B, "<a href="#RELNOTES">åè¡è¯´æ</a>", ååºäºæ¯æ¬¡mini-XMLåå¸çæ¬çæ¹åä¿¡æ¯.</li>
<li>éå½ C, "<a href="#REFERENCE">åºåèæå</a>", å
å«äºå
³äºmini-XMLçå®æ´åèä¿¡æ¯,ä½¿ç¨ <tt>mxmldoc</tt>çæ.</li>
<li>éå½ D, "<a href="#SCHEMA">XMLæ¹æ¡</a>", æ¾ç¤ºäº <tt>mxmldoc</tt> çæXMLæ件æ¶ä½¿ç¨ç XML æ¹æ¡.</li>
</ul>
<!-- NEED 10 -->
<h2><a name="1_2">è¯æ³çº¦å® </a></h2>
<p>å¨è¿ç¯æåä¸ä½¿ç¨äºä¸äºåä½åé£æ ¼ç约å®.ä¸é¢æ¯ä¸äºä¾åå«ä¹å使ç¨è¯´æ:</p>
<dl>
<dt><code>lpstat</code>
<br> <code>lpstat(1)</code></dt>
<dd>å½ä»¤å称;å¦æå¨ä¸ç« ä¸ç¬¬ä¸æ¬¡æåè¿ä¸ªç³»ç»å½ä»¤æè
å½æ°ï¼ååé¢è·éæå页ç¼å·ã<div class="zf">è¯è
ï¼ä¸é¢æLinux çmanpages æåï¼ä½¿ç¨manå½ä»¤æ¥çãZ.F</div>
<br>
<br></dd>
<dt><var>/var</var>
<br><var> /usr/share/cups/data/testprint.ps</var></dt>
<dd>æ件æè
ç®å½.
<br>
<br></dd>
<dt><tt>Request ID is Printer-123</tt></dt>
<dd>å±å¹è¾åº.
<br>
<br></dd>
<dt><kbd>lp -d printer filename ENTER</kbd></dt>
<dd>ç¨æ·è¾å
¥çæåï¼ç¹æ®é®å¦<kbd>ENTER</kbd> æ»æ¯ä½¿ç¨å¤§å.
<br>
<br></dd>
<dt>12.3</dt>
<dd>ææ¬ä¸çæ°åï¼ä½¿ç¨(.)æ¥è¡¨ç¤ºå°æ°ç¹.
<br>
<br></dd>
</dl>
<!-- NEED 10 -->
<h2><a name="1_3">缩ç¥è¯</a></h2>
<p>ä¸é¢æ¯å¨æ¬æåä¸ä½¿ç¨ç缩ç¥è¯:</p>
<dl>
<dt>Gb</dt>
<dd>GB, å³ 1073741824 åèï¼1*1024*1024*1024 åè
<br>
<br></dd>
<dt>kb</dt>
<dd> å³ 1024 åèï¼1*1024 åè
<br>
<br></dd>
<dt>Mb</dt>
<dd>å
, or 1048576 bytes,1*1024*1024 åè
<br>
<br></dd>
<dt>UTF-8, UTF-16</dt>
<dd>ç»ä¸çå符ç¼ç æ å, 8-ä½ æ 16-ä½
<br>
<br></dd>
<dt>W3C</dt>
<dd>ä¸ç»´ç½èç
<br>
<br></dd>
<dt>XML</dt>
<dd>å¯æ©å±æ è®°è¯è¨
<br>
<br></dd>
</dl>
<!-- NEED 12 -->
<h2><a name="1_4">å
¶ä»åè</a></h2>
<dl>
<dt>The Unicode Standard, Version 4.0, Addison-Wesley, ISBN
0-321-18578-1</dt>
<dd>å®ä¹äºç¨äºXMLçUnicodeå符é.
<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>W3Cå¶å®çXMLæ å.
<br>
<br></dd>
</dl>
<!-- NEED 6 -->
<h2><a name="1_5">æ³å¾èµæ</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
Library General Public License for more details.</p>
<hr noshade="noshade">
<h1 align="right"><a name="INSTALL"><img alt="1" src="minixml-cn_files/1.gif" align="right" height="100" hspace="10" width="100"></a>æ建ï¼å®è£
ï¼ä»¥åæå
Mini-XML </h1>
<p>è¿ä¸ç« æè¿°äºå¦ä½å¨ä½ çç³»ç»ä¸ä½¿ç¨æºç å
æ建ï¼å®è£
以åæå
Mini-XML,ä½ å°éè¦ä¸ä¸ªANSI/ISO-Cå
¼å®¹çCç¼è¯å¨æ¥æ建Mini-XML,GCCå¯ä»¥å·¥ä½ï¼è¿ä¹æ¯å¤§å¤æ°å家çCç¼è¯å¨ãå¦æä½ éè¦å¨Windowså¹³å°ä¸æå»ºï¼ æ们建议使ç¨Virtual C++ç¯å¢å解å³æ¹æ¡æ件.对äºå
¶ä»çæä½ç³»ç»ï¼ä½ å¨Cç¼è¯å¨ä¹å¤éè¦ä¸ä¸ªPOSIXå
¼å®¹çshellå<tt>make</tt>ç¨åº.
.</p>
<h2><a name="2_1">ç¼è¯ Mini-XML</a></h2>
<p>Mini-XML åæ¶å
·å¤åºäº autoconfçé
ç½®èæ¬åVirtual C++ç解å³æ¹æ¡ï¼å¯ä»¥ç¨æ¥ç¼è¯åºåå
³èçå
¶ä»å·¥å
·.</p>
<h3><a name="2_1_1">ä½¿ç¨ Visual C++ ç¼è¯</a></h3>
<p>æå¼å¨ç®å½<var> vcnet</var> ä¸ç<var> mxml.sln</var> 解å³æ¹æ¡.
éæ©éè¦æ建çé
ç½®,"Debug" (缺çé项) æè
"Release", å¹¶ä¸ ä»<var>
Build</var> èåä¸éæ©<var> Build Solution</var>项.</p>
<h3><a name="2_1_2">使ç¨å½ä»¤è¡å·¥å
·ç¼è¯</a></h3>
<p>å¨ä½ çç³»ç»ä¸é®å
¥ä¸é¢çå½ä»¤æ¥é
ç½®Mini-XMLæºä»£ç :</p>
<pre> <kbd>./configure ENTER</kbd>
</pre>
<p>缺ççå®è£
åç¼æ¯<var> /usr/local</var>, è¿å¯ä»¥è¢«è¦çä½¿ç¨ <kbd>--prefix</kbd> é项:</p>
<pre> <kbd>./configure --prefix=/foo ENTER</kbd>
</pre>
<p>å
¶ä»é
ç½®é项å¯ä»¥ä½¿ç¨å½ä»¤<kbd>--help</kbd>
é项è¿è¡æ¥ç:</p>
<pre> <kbd>./configure --help ENTER</kbd>
</pre>
<p>å½ä½ é
ç½®å®æ¯,使ç¨<tt>make(1)</tt>ç¨åºæ¥æ建并ä¸è¿è¡æµè¯ç¨åºæ¥æ ¡éªæ¯å¦å·¥ä½æ£å¸¸ï¼å¦ä¸ï¼
</p>
<pre> <kbd>make ENTER</kbd>
</pre>
<h2><a name="2_2">å®è£
Mini-XML</a></h2>
<p>å¦æä½ ä½¿ç¨ Visual C++, åå«æ·è´<var> mxml.lib</var> å <var>
mxml.h</var> æä»¶å° Visual C++<var> lib</var> å<var> include<var>
ç®å½.</var></var></p>
<p>å¦å,使ç¨<tt>make</tt> å½ä»¤å<kbd>install</kbd>åæ°æ¥å®è£
Mini-XMLå°é
ç½®çç®å½ä¸:</p>
<pre> <kbd>make install ENTER</kbd>
</pre>
<h2><a name="2_3">å建 Mini-XML å
</a></h2>
<p>Mini-XML å
å«ä¸¤ä¸ªæ件å¯ä»¥è¢«ç¨æ¥å建äºè¿å¶åè¡å
.第ä¸ä¸ªæ件æ¯<var> mxml.spec</var> å¯ä»¥è¢«ä½¿ç¨éè¿<tt>
rpmbuild(8)</tt> 软件æ¥å建Red Hat å
管çå¨("RPM")çåè¡å
ï¼é常ç¨äºLinuxå¹³å°. <tt>rpmbuild</tt>
å¯ä»¥èªå·±è¿è¡è½¯ä»¶ç¼è¯, ä½ å¯ä»¥ä¸ºå®æä¾ä¸ä¸ªMini-XML çtaræ件æ¥ç¼è¯æ´ä¸ªå
ï¼ä½¿ç¨ä»¥ä¸å½ä»¤:</p>
<pre> <kbd>rpmbuild -ta mxml-<i>version</i>.tar.gz ENTER</kbd>
</pre>
<p>第äºä¸ªæ件æ¯<var> mxml.list</var>被ç¨äº<tt>
epm(1)</tt> ç¨åºå建ä¸åæ ¼å¼ç软件å
.
<tt>epm</tt> ç¨åºå¯ä»¥ä»ä»¥ä¸ç½åè·å¾:</p>
<pre> <a href="http://www.easysw.com/epm/">http://www.easysw.com/epm/</a>
</pre>
<p>使ç¨<tt>make</tt> å½ä»¤éè¿ <kbd>epm</kbd> ç®æ æ¥æ建ä¸ä¸ªéå¯¹ä½ çç³»ç»ç便æºçæ¬å°å
:</p>
<pre> <kbd>make epm ENTER</kbd>
</pre>
<p>为äºä½ æ¹ä¾¿,è¿äºå
ä¿åå¨åç®å½<var> dist</var> ä¸.便æºå
å©ç¨èæ¬åtaræ件å®è£
软件å°ç®æ ç³»ç»ä¸.å¨å±å¼å
æ件å,使ç¨<var> mxml.install</var>èæ¬æ¥å®è£
è¿ä¸ªè½¯ä»¶.</p>
<p>è¿äºæ¬å°å
å¯ä»¥æ¯æ¬å°æä½ç³»ç»çåçæ ¼å¼:红帽Linux çRPM , Debian LinuxçDPKG, SolarisçPKG, çç.使ç¨ç¸åºçå½ä»¤æ¥å®è£
è¿äºåçå
.</p>
<hr noshade="noshade">
<h1 align="right"><a name="BASICS"><img alt="2" src="minixml-cn_files/2.gif" align="right" height="100" hspace="10" width="100"></a>Mini-XML å
¥é¨</h1>
<p>è¿ä¸ç« æè¿°äºå¦ä½åä¸ä¸ªç¨åºä½¿ç¨Mini-XMLæ¥è®¿é®XMLæ件ä¸çæ°æ®.Mini-XMLæä¾äºä»¥ä¸åè½:</p>
<ul>
<li>å¨å
åä¸å建å管çXMLææ¡£çå½æ°.</li>
<li>读UTF-8åUTF-16 ç¼ç çXMLæ件åå符串.</li>
<li>åUTF-8 ç¼ç çXMLæ件åå符串.</li>
<li>æ¯æä»»æçå
ç´ å称ï¼å±æ§ä»¥åå±æ§å¼ï¼æ²¡æä»»ä½å
¶ä»éå¶ï¼ä»
åéäºææå
å.</li>
<li>æ¯ææ´å½¢ãæµ®ç¹ãèªå®ä¹("CDATA")åææ¬æ°æ®ç±»åå¨"å¶"èç¹.</li>
<li>æä¾"æ¥æ¾"ã"ç´¢å¼"ã以å"æ¥è¿"å½æ°å¯ä»¥å¾ç®åç访é®XMLææ¡£ä¸çæ°æ®.</li>
</ul>
<p>Mini-XML ä¸è¿è¡åºäº"XMLæ¹æ¡(SCHEMA)"æ件æè
å
¶ä»å
容æºå®ä¹ä¿¡æ¯çæ ¡éªåå
¶ä»ç±»åçå¤ç ,ä¹ä¸æ¯æå
¶ä»ç»ç»æè¦æ±çXMLè§è.</p>
<h2><a name="3_1">åºç¡ç¥è¯</a></h2>
<p>Mini-XML æä¾çä¸ä¸ªä½ éè¦å
å«ç头æ件:</p>
<pre> #include <mxml.h>
</pre>
<p>æMini-XMLåºè¿æ¥å°ä½ çåºç¨ç¨åºä½¿ç¨<kbd>
-lmxml</kbd> é项:</p>
<pre> <kbd>gcc -o myprogram myprogram.c -lmxml ENTER</kbd>
</pre>
<p>å¦æä½ å·²ç»å®è£
<tt>pkg-config(1)</tt> 软件, ä½ å¯ä»¥ä½¿ç¨å®æ¥ä¸ºä½ çå®è£
ç¡®å®éå½çç¼è¯åè¿æ¥é项:</p>
<pre> <kbd>pkg-config --cflags mxml ENTER</kbd>
<kbd>pkg-config --libs mxml ENTER</kbd>
</pre>
<h2><a name="3_2">èç¹</a></h2>
<p>æ¯ä¸åXMLæ件ä¸çä¿¡æ¯çæ(å
ç´ ãææ¬ãæ°å)æ¯ä¸ä¸ªåå¨å¨å
åä¸ç"èç¹(nodes)"
.èç¹ä½¿ç¨<a href="#mxml_node_t">
<tt>mxml_node_t</tt></a> ç»æè¿è¡å®ä¹. å®ç<a href="#mxml_type_t"><tt>type</tt>
</a> æååéå®ä¹äºèç¹ç±»åï¼element, integer, opaque, real, or
text) å³å®äºéè¦ä»èå(union)ç±»åçæååé<a href="#mxml_value_t">
<tt>value</tt></a> ä¸è·åçå¼.</p>
<!-- NEED 10 -->
<center>
<table summary="Mini-XML Node Value Members" border="1" cellpadding="5" cellspacing="0" width="80%"><caption align="bottom"><i> 表 2-1: Mini-XML èç¹å¼çæååé
</i></caption>
<tbody><tr bgcolor="#cccccc"><th>å¼</th><th>ç±»å</th><th>èç¹æå</th></tr>
<tr><td>ç¨æ·å®ä¹</td><td><tt>void *</tt></td><td><tt>
node->value.custom.data</tt></td></tr>
<tr><td>XMLå
ç´ </td><td><tt>char *</tt></td><td><tt>
node->value.element.name</tt></td></tr>
<tr><td>æ´æ°</td><td><tt>int</tt></td><td><tt>node->value.integer</tt>
</td></tr>
<tr><td>ä¸éæå符串</td><td><tt>char *</tt></td><td><tt>
node->value.opaque</tt></td></tr>
<tr><td>æµ®ç¹æ°</td><td><tt>double</tt></td><td><tt>node->value.real</tt></td>
</tr>
<tr><td>ææ¬</td><td><tt>char *</tt></td><td><tt>node->value.text.string</tt>
</td></tr>
</tbody></table>
</center>
<div class="zf">è¯è
ï¼èç¹ç±»åå®ä¹æ举åè§ï¼<a href="#mxml_type_e">mxml_type_e</a>ãMini-XMLä¸çèç¹ç±»åå®ä¹åå
¶ä»æäºè§£æå¨æäºä¸åï¼å
¶ä¸æ´æ°ãæµ®ç¹ãåææ¬èç¹æ¯æå¨ä¸ä¸ªXMLå
ç´ ä¸ä¸ç³»åç使ç¨ç©ºæ ¼ä½ä¸ºåå²çå¼ï¼æ¯ä¸ªå
ç´ å¯ä»¥æ¥æå¤ä¸ªä»¥ä¸èç¹ï¼å¹¶å¯ä»¥éæ©ä½¿ç¨ç©ºæ ¼åå¼ï¼å¦ï¼<abc>aa bb cc</abc>ï¼Mini-MXMLå¨ä½¿ç¨åæ°ï¼MXML_TEXT_CALLBACKè¿è¡è½½å
¥æ¶ï¼å°å¨abcå
ç´ ä¸é¢çæ3个textç±»åçåèç¹ãå¨å建æ¶ä¹å¯ä»¥ä½¿ç¨åæ ·çæ¹å¼å建èç¹ãæ´æ°åæµ®ç¹ä¹æ¯åæ ·æ¹å¼ï¼ä½å¦æ转æ¢å¤±è´¥åMiniXMLæ¥éãèä¸éæå符串类å(OPAQUE)åä¸è¿è¡å符串åå²ï¼å¨è½½å
¥æ¶éè¦ä½¿ç¨MXML_OPAQUE_CALLBACKåæ°ï¼å°ææå符串形æä¸ä¸ªåèç¹ã详æ
è§ï¼<a href="#ADVANCED">使ç¨å è½½åè°å½æ°</a>ã Z.F</div>
<p>æ¯ä¸ä¸ªèç¹æ»æ¯æä¸ä¸ªæååé:<tt>user_data</tt> å¯ä»¥å
è®¸ä½ ä¸ºæ¯ä¸ä¸ªèç¹å
³èä½ éè¦çåºç¨æ°æ®.</p>
<p>æ°çèç¹å¯ä»¥ä½¿ç¨ä»¥ä¸å½æ°è¿è¡å建 <a href="#mxmlNewElement"><tt>
mxmlNewElement</tt></a>, <a href="#mxmlNewInteger"><tt>mxmlNewInteger</tt>
</a>, <a href="#mxmlNewOpaque"><tt>mxmlNewOpaque</tt></a>, <a href="#mxmlNewReal">
<tt>mxmlNewReal</tt></a>, <a href="#mxmlNewText"><tt>mxmlNewText</tt></a>
<a href="#mxmlNewTextf"><tt>mxmlNewTextf</tt></a> <a href="#mxmlNewXML">
<tt>mxmlNewXML</tt></a> . åªæ elements å¯ä»¥æ¥æåèç¹ï¼é¡¶çº§èç¹å¿
é¡»æ¯ä¸ä¸ª element , é常æ¯<tt><?xml
version="1.0"?></tt> 使ç¨<tt>mxmlNewXML()</tt>å½æ°å建çèç¹.</p>
<p>æ¯ä¸ªèç¹é½æä¸äºå
³èèç¹çæéï¼ä¸(<tt>parent</tt>), ä¸(<tt>
child</tt>), å·¦(<tt>prev</tt>), and å³(<tt>next</tt>) ç¸å¯¹åºäºå½åèç¹. å¦æä½ æä¸ä¸ªXMLæ件å¦ä¸æ示:</p>
<pre> <?xml version="1.0"?>
<data>
<node>val1</node>
<node>val2</node>
<node>val3</node>
<group>
<node>val4</node>
<node>val5</node>
<node>val6</node>
</group>
<node>val7</node>
<node>val8</node>
</data>
</pre>
<p>é£ä¹å¨å
åä¸çæ件èç¹æ çä¸å»å¦ä¸æ示:</p>
<pre> ?xml
|
data
|
node - node - node - group - node - node
| | | | | |
val1 val2 val3 | val7 val8
|
node - node - node
| | |
val4 val5 val6
</pre>
<p>è¿é"-"æåä¸ä¸ä¸ªèç¹ï¼"|"æå第ä¸ä¸ªåèç¹ã</p>
<p>å½ä½ 使ç¨å®æ¯è¿äºXMLæ°æ®åï¼ä½¿ç¨å½æ°<a href="#mxmlDelete"><tt>
mxmlDelete</tt></a> æ¥éæ¾æå®èç¹æè
æ´ä¸ªXMLæ èç¹åå®ä¸é¢ææåèç¹çå
å:</p>
<pre> mxmlDelete(tree);
</pre>
<!-- NEW PAGE -->
<h2><a name="3_3">å建 XML ææ¡£</a></h2>
<p>ä½ å¯ä»¥å¨å
åä¸å建åæ´æ°XMLææ¡£ï¼ä½¿ç¨<tt>
mxmlNew</tt> ä¸ç³»åå½æ°. ä¸é¢ç代ç å°å建ä¸ä¸ç« æè¿°çXMLææ¡£:</p>
<pre> mxml_node_t *xml; /* <?xml ... ?> */
mxml_node_t *data; /* <data> */
mxml_node_t *node; /* <node> */
mxml_node_t *group; /* <group> */
xml = mxmlNewXML("1.0");
data = mxmlNewElement(xml, "data");
node = mxmlNewElement(data, "node");
mxmlNewText(node, 0, "val1");
node = mxmlNewElement(data, "node");
mxmlNewText(node, 0, "val2");
node = mxmlNewElement(data, "node");
mxmlNewText(node, 0, "val3");
group = mxmlNewElement(data, "group");
node = mxmlNewElement(group, "node");
mxmlNewText(node, 0, "val4");
node = mxmlNewElement(group, "node");
mxmlNewText(node, 0, "val5");
node = mxmlNewElement(group, "node");
mxmlNewText(node, 0, "val6");
node = mxmlNewElement(data, "node");
mxmlNewText(node, 0, "val7");
node = mxmlNewElement(data, "node");
mxmlNewText(node, 0, "val8");
</pre>
<p>æ们é¦å
使ç¨<a href="#mxmlNewXML"><tt>mxmlNewXML</tt></a>å½æ°æ¥å建ææXMLæ件é½éè¦çæ 头 <tt><?xml version="1.0"?></tt>
:</p>
<pre> xml = mxmlNewXML("1.0");
</pre>
<p>ç¶åæ们使ç¨<a href="#mxmlNewElement"><tt>mxmlNewElement</tt></a>å½æ°æ¥å建æ¬æ件使ç¨ç<tt><data></tt>èç¹.第ä¸ä¸ªåæ°æå®äºç¶èç¹(<tt>xml</tt>) ï¼ç¬¬äºä¸ªåæ°æ¯å
ç´ å (<tt>data</tt>):</p>
<pre> data = mxmlNewElement(xml, "data");
</pre>
<p>æ¯ä¸ªå¨æ¬æ件ä¸<tt><node>...</node></tt>ä¹é´çé¨å使ç¨å½æ°<a href="#mxmlNewElement"><tt>
mxmlNewElement</tt></a> å <a href="#mxmlNewText"><tt>mxmlNewText</tt></a>æ¥å建. <tt>mxmlNewText</tt> ç第ä¸ä¸ªåæ°æå®äºç¶èç¹ (<tt>node</tt>).第äºä¸ªåæ°æå®äºæ¯å¦å¨ææ¬ä¹åæ·»å 空ç½å符ï¼å¨æ¬ä¾ä¸ä½¿ç¨0æè
false.æåä¸ä¸ªåæ°æå®äºéè¦æ·»å çå®é
ææ¬:</p>
<pre> node = mxmlNewElement(data, "node");
mxmlNewText(node, 0, "val1");
</pre>
<p>å¨å
åä¸çXMLç»æå¯ä»¥è¢«ä¿åæè
è¿è¡å
¶ä»å¤çï¼å°±åä¸ä¸ªä»ç£çæè
å符串ä¸è¯»åçææ¡£ä¸æ ·.</p>
<!-- NEW PAGE -->
<h2><a name="3_4">å è½½XML</a></h2>
<p>ä½ å¯ä»¥å è½½ä¸ä¸ªXMLæ件使ç¨å½æ°<a href="#mxmlLoadFile"><tt>
mxmlLoadFile</tt></a> :</p>
<pre> FILE *fp;
mxml_node_t *tree;
fp = fopen("filename.xml", "r");
tree = mxmlLoadFile(NULL, fp,
MXML_TEXT_CALLBACK);
fclose(fp);
</pre>
<p>第ä¸ä¸ªåæ°å¦ææçè¯åæå®äºä¸ä¸ªåå¨çXMLç¶èç¹.ä¸è¬ä½ å°è¿ä¸ªåæ°çäº<tt>NULL</tt>,é¤éä½ æ³è¦è¿æ¥å¤ä¸ªXMLæº. å¦ææ¤åæ°çäº<tt>NULL</tt>ï¼é£ä¹æå®çXMLæ件å¿
é¡»æ¯ä¸ä¸ªå®æ´çXMLææ¡£ï¼æ档头é¨è¦å
å«<tt>?xml</tt>å
ç´ .</p>
<p>第äºä¸ªåæ°æå®äºä¸ä¸ªæ åçæ件æµï¼ä½¿ç¨ <tt>fopen()</tt> æè
<tt>popen()</tt>è¿è¡æå¼. ä½ ä¹å¯ä»¥ä½¿ç¨<tt>stdin</tt>ï¼å¦æä½ æ³è¦å®ç°ä¸ä¸ªXMLè¿æ»¤å¨ç¨åº.</p>
<p>第ä¸ä¸ªåæ°æå®äºä¸ä¸ªåè°å½æ°ç¨äºä¸ä¸ªæ°çXMLå
ç´ èç¹ç´æ¥è¿åçåèç¹çå¼ç±»å: <tt>
MXML_CUSTOM</tt>, <tt>MXML_IGNORE</tt>, <tt>MXML_INTEGER</tt>, <tt>
MXML_OPAQUE</tt>, <tt>MXML_REAL</tt>, or <tt>MXML_TEXT</tt>. å è½½åè°å½æ°çç»èå¨<a href="#LOAD_CALLBACKS">第ä¸ç« </a>åäºè¯¦ç»æè¿°. 示ä¾ä»£ç ä½¿ç¨ <tt>MXML_TEXT_CALLBACK</tt> 常éæå®ææ¡£ä¸ææçæ°æ®èç¹é½å
å«ä½¿ç¨ä»¥ç©ºæ ¼å符åå²çææ¬çå¼. å
¶ä»æ åçåè°è¿æ<tt>
MXML_IGNORE_CALLBACK</tt>, <tt>MXML_INTEGER_CALLBACK</tt>, <tt>
MXML_OPAQUE_CALLBACK</tt>, å<tt>MXML_REAL_CALLBACK</tt>.</p>
<p>å½æ°<a href="#mxmlLoadString"><tt>mxmlLoadString</tt></a> å¯ä»¥ä»ä¸ä¸ªå符串ä¸è½½å
¥XMLèç¹æ :</p>
<!-- NEED 10 -->
<pre> char buffer[8192];
mxml_node_t *tree;
...
tree = mxmlLoadString(NULL, buffer,
MXML_TEXT_CALLBACK);
</pre>
<p>第ä¸ä¸ªå第ä¸ä¸ªåæ°å<tt>
mxmlLoadFile()</tt>ç¨æ³ä¸æ ·. 第äºä¸ªåæ°æå®äºæå®äºå符串æè
å符ç¼å²åºç¨äºå è½½XMLï¼å½ç¶èç¹åæ°ä¸º<tt>NULL</tt>æ¶å
容å¿
须为å®æ´çXMLææ¡£ï¼å
æ¬XML头<tt>?xml</tt>å
ç´ .</p>
<!-- NEW PAGE -->
<h2><a name="3_5">ä¿å XML</a></h2>
<p>ä½ å¯ä»¥ä¿åXMLæ件使ç¨<a href="#mxmlSaveFile"><tt>
mxmlSaveFile</tt></a> å½æ°:</p>
<pre> FILE *fp;
mxml_node_t *tree;
fp = fopen("filename.xml", "w");
mxmlSaveFile(tree, fp, MXML_NO_CALLBACK);
fclose(fp);
</pre>
<p>第ä¸ä¸ªåæ°ä¸ºæ³è¦ä¿åçXMLèç¹æ ,ä¸è¬åºè¯¥æ¯ä¸ä¸ªæåä½ çXMLæ档顶级èç¹<tt>?xml</tt>çèç¹æé.</p>
<p>第äºä¸ªåæ°æ¯ä¸ä¸ªæ åæ件æµï¼ä½¿ç¨<tt>
fopen()</tt> æè
<tt>popen()</tt>æ¥æå¼. ä½ ä¹å¯ä»¥ä½¿ç¨<tt>stdout</tt> å¦æä½ æ³è¦å®ç°ä¸ä¸ªXMLè¿æ»¤å¨ç¨åº.</p>
<p>第ä¸ä¸ªåæ°æ¯ä¸ä¸ªç©ºç½åè°å½æ°ç¨æ¥æ§å¶ä¿åæ件æ¶æå
¥ç"空ç½"å符."空ç½åè°"ç详ç»ä¿¡æ¯åè§<a href="#SAVE_CALLBACKS">
第ä¸ç« </a>. 以ä¸ç示ä¾ä»£ç 使ç¨äº<tt>MXML_NO_CALLBACK</tt>常éæ¥æå®ä¸éè¦ç¹å«ç空ç½å¤ç.</p>
<p>å½æ°<a href="#mxmlSaveAllocString"><tt>mxmlSaveAllocString</tt></a>,
å<a href="#mxmlSaveString"><tt>mxmlSaveString</tt></a> ä¿åXMLèç¹æ å°ä¸ä¸ªå符串ä¸:</p>
<pre> char buffer[8192];
char *ptr;
mxml_node_t *tree;
...
mxmlSaveString(tree, buffer, sizeof(buffer),
MXML_NO_CALLBACK);
...
ptr = mxmlSaveAllocString(tree, MXML_NO_CALLBACK);
</pre>
<p>第ä¸ä¸ªåæåä¸ä¸ªåæ°çç¨æ³åå½æ°<tt>
mxmlSaveFile()</tt>ä¸æ ·. å½æ°<tt>mxmlSaveString</tt> ç»åºäºä¸ä¸ªæéåé¿åº¦çåæ°æ¥ä¿åXMLææ¡£å°ä¸ä¸ªåºå®å¤§å°çç¼å²åºä¸ã,
<tt>mxmlSaveAllocString()</tt> è¿åäºä½¿ç¨mallocåé
çä¸ä¸ªå符串ç¼å²åº<tt>malloc()</tt>.</p>
<h3><a name="3_5_1">èªå¨æè¡æ§å¶</a></h3>
<p>å½æ们ä¿åXMLææ¡£æ¶, Mini-XMLä¸è¬å¨ç¬¬75åè¿è¡æè¡ï¼å 为è¿æ ·å¨ç»ç«¯ä¸ææ读. å½æ°<a href="#mxmlSetWrapMargin">
<tt>mxmlSetWrapMargin</tt></a> å¯ä»¥è¦ç缺ççæè¡çé:</p>
<pre> /* 设置èªå¨æè¡å° 132 å*/
mxmlSetWrapMargin(132);
/* åæ¶èªå¨æè¡*/
mxmlSetWrapMargin(0);
</pre>
<!-- NEW PAGE-->
<h2><a name="3_6">æç´¢åéåèç¹</a></h2>
<p>å½æ°<a href="#mxmlWalkPrev"><tt>mxmlWalkPrev</tt></a> and <a href="#mxmlWalkNext">
<tt>mxmlWalkNext</tt></a>å¯ä»¥è¢«ç¨æ¥éåXMLèç¹æ :</p>
<pre> mxml_node_t *node;
node = mxmlWalkPrev(current, tree,
MXML_DESCEND);
node = mxmlWalkNext(current, tree,
MXML_DESCEND);
</pre>
<p>å¦å¤,ä½ å¯ä»¥æç´¢ä¸ä¸ªå½åçXMLå
ç´ /èç¹,使ç¨å½æ°<a href="#mxmlFindElement">
<tt>mxmlFindElement</tt></a>:</p>
<pre> mxml_node_t *node;
node = mxmlFindElement(tree, tree, "name",
"attr", "value",
MXML_DESCEND);
</pre>
<p>åæ°<tt>name</tt>, <tt>attr</tt>, å<tt>value</tt> å¯ä»¥è¢«è®¾ç½®ä¸º<tt>NULL</tt>ä½ä¸ºå
¨é¨å¹é
, e.g.:</p>
<!-- NEED 4 -->
<pre> /* æ索第ä¸ä¸ª "a" å
ç´ */
node = mxmlFindElement(tree, tree, "a",
NULL, NULL,
MXML_DESCEND);
</pre>
<!-- NEED 5 -->
<pre> /* æ索第ä¸ä¸ª"a" å
ç´ å¹¶å
å«"href"å±æ§*/
node = mxmlFindElement(tree, tree, "a",
"href", NULL,
MXML_DESCEND);
</pre>
<!-- NEED 6 -->
<pre> /* æ索第ä¸ä¸ª"a" å
ç´ å¹¶ä¸å
å«"href"å±æ§çäºç»åºçURL */
node = mxmlFindElement(tree, tree, "a",
"href",
"http://www.easysw.com/",
MXML_DESCEND);
</pre>
<!-- NEED 5 -->
<pre> /* æ索第ä¸ä¸ªå
å«"src"å±æ§çXMLå
ç´ */
node = mxmlFindElement(tree, tree, NULL,
"src", NULL,
MXML_DESCEND);
</pre>
<!-- NEED 5 -->
<pre> /* æ索第ä¸ä¸ªå
å«"src"= "foo.jpg"å±æ§çXMLå
ç´ */
node = mxmlFindElement(tree, tree, NULL,
"src", "foo.jpg",
MXML_DESCEND);
</pre>
<p>ä½ ä¹å¯ä»¥ä½¿ç¨åæ ·çåè½è¿è¡éå:</p>
<pre> 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 ...
}
</pre>
<!-- NEED 10 -->
<p>åæ°<tt>MXML_DESCEND</tt>å¯ä»¥æ¯ä¸é¢ä¸ä¸ªå¸¸éä¹ä¸:</p>
<ul>
<li><tt>MXML_NO_DESCEND</tt> å«ä¹æ¯ä¸æ¥çä»»ä½çåèç¹å¨XMLå
ç´ å±æ¬¡ä¸ï¼ä»
æ¥çå级çä¼ä¼´èç¹æè
ç¶èç¹ç´å°å°è¾¾é¡¶çº§èç¹æè
ç»åºçæ ç顶级èç¹.
<p>"group"èç¹çä¸ä¸ä¸ªèç¹æ¶å®å·¦é¢ç"node"åèç¹,ä¸ä¸ä¸ªèç¹æ¯"group"å³é¢ç"node"åèç¹..
<br>
<br></p>
</li>
<li><tt>MXML_DESCEND_FIRST</tt>å«ä¹æ¯åä¸æç´¢å°ä¸ä¸ªèç¹ç第ä¸ä¸ªå¹é
åèç¹ï¼ä½ä¸å继ç»åä¸æç´¢ãä½ ä¸è¬ä½¿ç¨äºéåä¸ä¸ªç¶èç¹çç´æ¥çåèç¹ã
,å¦ï¼å¨ä¸é¢çä¾åä¸çææå¨"?xml"ç¶èç¹ä¸çææç"node"å"group"åèç¹ã.
<p>è¿ä¸ªæ¨¡å¼ä»
éç¨äºæç´¢(search)åè½ï¼éååè½(walk)对å¾
å®å <tt>MXML_DESCEND</tt> ä¸æ ·ï¼å 为æ¯æ¬¡è°ç¨é½æ¯é¦æ¬¡è°ç¨ã
<br>
<br></p>
</li>
<li><tt>MXML_DESCEND</tt>å«ä¹æ¯ä¸ç´åä¸ç´å°æ çæ ¹é¨. "group"èç¹çä¸ä¸ä¸ªèç¹å°æ¯"val3"èç¹ï¼ä¸ä¸ä¸ªèç¹å°æ¯"group"çä¸é¢ç第ä¸ä¸ªåèç¹ã
<p>å¦æä½ è¦ä½¿ç¨å½æ°<tt>mxmlWalkNext()</tt>ä»æ ¹ç»ç¹"?xml" éåå°æ´ä¸ªæ çç»æ, é£ä¹è¿ä¸ªé¡ºåºå°å¦ä¸æ示ï¼</p>
<p><tt>?xml data node val1 node val2 node val3 group node val4 node val5
node val6 node val7 node val8</tt></p>
<p>å¦æä½ ä»"val8"å¼å§å¹¶ä½¿ç¨å½æ°<tt>mxmlWalkPrev()</tt>è¿è¡éå,
è¿ä¸ªé¡ºåºå°æ¯åçï¼ç»æäº"?xml"èç¹.</p>
</li>
</ul>
<hr noshade="noshade">
<h1 align="right"><a name="ADVANCED"><img alt="3" src="minixml-cn_files/3.gif" align="right" height="100" hspace="10" width="100"></a>æ´å¤ç Mini-XML ç¼ç¨ææ¯</h1>
<p>è¿ä¸ç« æ¾ç¤ºäºæ´å¤çå¨ä½ çåºç¨ç¨åºä¸ä½¿ç¨Mini-XMLçæ¹æ³ã</p>
<h2><a name="LOAD_CALLBACKS">Load Callbacks</a></h2>
<p><a href="#LOAD_XML">第äºç« </a> ä»ç»äºå½æ°<a href="#mxmlLoadFile">
<tt>mxmlLoadFile()</tt></a> å<a href="#mxmlLoadString"><tt>
mxmlLoadString()</tt></a> . è¿äºå½æ°çæåä¸ä¸ªåæ°æ¯ä¸ä¸ªåè°å½æ°ï¼å³å®äºå¨ä¸ä¸ªXMLææ¡£ä¸æ¯ä¸ªæ°æ®èç¹çå¼çç±»åã</p>
<p>Mini-XML 为ç®åXMLæ°æ®æ件å®ä¹äºå 个æ åçåè°å½æ°ï¼</p>
<ul>
<li><tt>MXML_INTEGER_CALLBACK</tt> - ææçæ°æ®èç¹å
å«ä»¥ç©ºæ ¼åå²çæ´æ°ã</li>
<li><tt>MXML_OPAQUE_CALLBACK</tt> - ææçæ°æ®èç¹å
å«"ä¸éæ"å符串ï¼CDATAï¼ã</li>
<li><tt>MXML_REAL_CALLBACK</tt> - ææçæ°æ®èç¹å
å«ä»¥ç©ºæ ¼åå²çæµ®ç¹æ°ã</li>
<li><tt>MXML_TEXT_CALLBACK</tt> - ææçæ°æ®èç¹å
å«ä»¥ç©ºæ ¼åå²çææ¬å符串ã</li>
</ul>
<p>ä½ å¯ä»¥ä¸ºæ´å¤æçXMLææ¡£æä¾ä½ èªå·±çåè°å½æ°ãä½ çåè°å½æ°å°æ¥æ¶å°ä¸ä¸ªå°å½åXMLå
ç´ èç¹çæé并ä¸å¿
须为è¿ä¸ªXMLå
ç´ èç¹è¿åä¸ä¸ªç´æ¥åèç¹çå¼ç±»å: <tt>MXML_INTEGER</tt>, <tt>MXML_OPAQUE</tt>, <tt>
MXML_REAL</tt>, æ<tt>MXML_TEXT</tt>.è¿ä¸ªå½æ°å¨è¿ä¸ªXMLå
ç´ åå®çå
¨é¨å±æ§è¢«è¯»å<i>以å</i>被è°ç¨ï¼æä»¥ä½ å¯ä»¥æ¥çè¿ä¸ªXMLå
ç´ çå称ãå±æ§ä»¥åå±æ§çå¼æ¥å³å®éå½çè¿åå¼ç±»åã </p>
<!-- NEED 2in -->
<p>ä¸é¢çåè°å½æ°æ¥çä¸ä¸ªå称为"type"çå±æ§æè
XMLå
ç´ çååæ¥å³å®å®çåèç¹çå¼ç±»åï¼</p>
<pre> mxml_type_t
type_cb(mxml_node_t *node)
{
const char *type;
/*
* ä½ å¯ä»¥æ¥çå±æ§å/æ使ç¨XMLå
ç´ åï¼æå¨å±æ¬¡ï¼çç
*/
type = mxmlElementGetAttr(node, "type");
if (type == NULL)
type = node->value.element.name;
if (!strcmp(type, "integer"))
return (MXML_INTEGER);
else if (!strcmp(type, "opaque"))
return (MXML_OPAQUE);
else if (!strcmp(type, "real"))
return (MXML_REAL);
else
return (MXML_TEXT);
}
</pre>
<p>è¦ä½¿ç¨è¿ä¸ªåè°å½æ°ï¼åªéè¦å¨ä½ è°ç¨ä»»ä½å è½½å½æ°æ¶ç®åç使ç¨å®çååï¼</p>
<pre> FILE *fp;
mxml_node_t *tree;
fp = fopen("filename.xml", "r");
tree = mxmlLoadFile(NULL, fp, <b>type_cb</b>);
fclose(fp);
</pre>
<h2><a name="SAVE_CALLBACKS">ä¿ååè°</a></h2>
<p><a href="#LOAD_XML">第äºç« </a> ä¹ä»ç»äº<a href="#mxmlSaveFile">
<tt>mxmlSaveFile()</tt></a>, <a href="#mxmlSaveString"><tt>
mxmlSaveString()</tt></a>, å<a href="#mxmlSaveAllocString"><tt>
mxmlSaveAllocString()</tt></a> å½æ°ãè¿äºå½æ°çæåä¸ä¸ªåæ°æ¯ä¸ä¸ªåè°å½æ°è¢«ç¨æ¥èªå¨å¨ä¸ä¸ªXMLææ¡£ä¸æ·»å 空ç½å符ã</p>
<p>ä½ çåè°å½æ°å°å¨æ¯ä¸ªXMLå
ç´ è¢«è°ç¨å次ï¼ä¼ å
¥åæ°ä¸ºä¸ä¸ªå°è¿ä¸ªèç¹çæéåä¸ä¸ª"where"çå¼ï¼<tt>
MXML_WS_BEFORE_OPEN</tt>, <tt>MXML_WS_AFTER_OPEN</tt>, <tt>
MXML_WS_BEFORE_CLOSE</tt>, æè
<tt>MXML_WS_AFTER_CLOSE</tt>ãå¦æä¸éè¦æå
¥ç©ºç½å符è¿ä¸ªåè°å½æ°å°è¿å <tt>NULL</tt>ï¼å¦åè¿åå符串ï¼ç©ºç½ãè·³æ ¼ãå车åæ¢è¡ï¼å°è¢«æå
¥ã</p>
<p>ä¸é¢ç空ç½åè°å¯ä»¥è¢«ç¨æ¥ä¸ºXHTMLè¾åºæ·»å 空ç½å符ï¼æ¥ä½¿å®å¨ä¸è¬çææ¬ç¼è¾å¨ä¸æ´å æ读ï¼</p>
<pre> const char *
whitespace_cb(mxml_node_t *node,
int where)
{
const char *name;
/*
* æ们å¯ä»¥å¨ä»»ä½XMLå
ç´ ä¹åæä¹åææ¡ä»¶çæ·»å æ¢è¡ãè¿äºæ¯ä¸äºå¸¸è§çHTMLå
ç´ ã
*/
name = node->value.element.name;
if (!strcmp(name, "html") ||
!strcmp(name, "head") ||
!strcmp(name, "body") ||
!strcmp(name, "pre") ||
!strcmp(name, "p") ||
!strcmp(name, "h1") ||
!strcmp(name, "h2") ||
!strcmp(name, "h3") ||
!strcmp(name, "h4") ||
!strcmp(name, "h5") ||
!strcmp(name, "h6"))
{
/*
* å¨æå¼ä¹ååå
³éä¹åæ¶æ¢è¡ã
*/
if (where == MXML_WS_BEFORE_OPEN ||
where == MXML_WS_AFTER_CLOSE)
return ("\n");
}
else if (!strcmp(name, "dl") ||
!strcmp(name, "ol") ||
!strcmp(name, "ul"))
{
/*
* å¨å表å
ç´ ååé½æ·»å æ¢è¡ã
*/
return ("\n");
}
else if (!strcmp(name, "dd") ||
!strcmp(name, "dt") ||
!strcmp(name, "li"))
{
/*
* æ·»å ä¸ä¸ª"è·³æ ¼"å¨<li>, * <dd>,
* å <dt>ä¹å, 以åä¸ä¸ªæ¢è¡å¨ä»ä»¬åé¢...
*/
if (where == MXML_WS_BEFORE_OPEN)
return ("\t");
else if (where == MXML_WS_AFTER_CLOSE)
return ("\n");
}
/*
* å¦æä¸éè¦æ·»å 空ç½å符åè¿åNULLã
*/
return (NULL);
}
</pre>
<p>è¦ä½¿ç¨è¿äºåè°å½æ°ï¼åªéè¦å¨ä½ è°ç¨ä»»ä½ä¿åå½æ°æ¶ç®å使ç¨å®çååï¼</p>
<pre> FILE *fp;
mxml_node_t *tree;
fp = fopen("filename.xml", "w");
mxmlSaveFile(tree, fp, <b>whitespace_cb</b>);
fclose(fp);
</pre>
<!-- NEED 10 -->
<h2><a name="4_3">ç¨æ·å®ä¹æ°æ®ç±»å</a></h2>
<p>Mini-XML æ¯æéè¿å
¨å±çè½½å
¥åä¿ååè°å½æ°ä½¿ç¨èªå®ä¹æ°æ®ç±»åã æ¯æ¬¡åªè½æä¸ç»åè°å½æ°è¢«åæ¶æ¿æ´»ï¼ç¶èä½ çåè°å½æ°å¯ä»¥ä¸ºæ¯æå¤ç§æéè¦çèªå®ä¹æ°æ®ç±»åæ¥ä¿åæ´å¤çä¿¡æ¯ã èç¹ç±»å <tt>MXML_CUSTOM</tt>
表示ä¸ä¸ªèªå®ä¹æ°æ®å
容çèç¹ã</p>
<p>å è½½åè°æ¥æ¶ä¸ä¸ªå°å½åæ°æ®èç¹çæéåä¸ä¸ªä¸éæå符串æ°æ®ä»XMLæºä¸å¹¶ä¸å°å符é转æ¢ä¸ºUTF-8ç¼ç ãä¾å¦ï¼å¦ææ们æ³è¦æ¯æå®å¶çæ¥æ/æ¶é´ç±»å并ä¸ç¼ç 为"yyyy-mm-ddThh:mm:ssZ" (ISO æ ¼å¼), é£ä¹å è½½åè°å½æ°å¦ä¸æ示ï¼</p>
<pre> typedef struct
{
unsigned year, /* Year */
month, /* Month */
day, /* Day */
hour, /* Hour */
minute, /* Minute */
second; /* Second */
time_t unix; /* UNIX time */
} iso_date_time_t;
int
load_custom(mxml_node_t *node,
const char *data)
{
iso_date_time_t *dt;
struct tm tmdata;
/*
* åé
æ°æ®ç»æ...
*/
dt = calloc(1, sizeof(iso_date_time_t));
/*
* å°è¯ä»æ°æ®å符串ä¸è¯»å6个æ 符å·æ´æ°..
*/
if (sscanf(data, "%u-%u-%uT%u:%u:%uZ",
&(dt->year), &(dt->month),
&(dt->day), &(dt->hour),
&(dt->minute),
&(dt->second)) != 6)
{
/*
* å¦æä¸è½è¯»åå°æ°åï¼éæ¾åé
çç»æ并è¿åä¸ä¸ªé误...
*/
free(dt);
return (-1);
}
/*
* æ°æ®èå´æ£æ¥...
*/
if (dt->month <1 || dt->month > 12 ||
dt->day <1 || dt->day > 31 ||
dt->hour <0 || dt->hour > 23 ||
dt->minute <0 || dt->minute > 59 ||
dt->second <0 || dt->second > 59)
{
/*
* å¦ææ¥æä¿¡æ¯è¶
åºèå´...
*/
free(dt);
return (-1);
}
/*
* 转æ¢ISOæ¶é´å°ä»¥ç§ä¸ºåä½çUNIXæ¶é´...
*/
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;
dt->unix = gmtime(&tmdata);
/*
* 设置èªå®ä¹èç¹æ°æ®æéåéæ¯å½æ°æé...
*/
node->value.custom.data = dt;
node->value.custom.destroy = free;
/*
* è¿å没æé误...
*/
return (0);
}
</pre>
<p>è¿ä¸ªå½æ°æåæ¶è¿å0ï¼å½ä¸è½æ£ç¡®è§£ç èªå®ä¹æ°æ®æè
æ°æ®å
容é误æ¶è¿å-1ãèªå®ä¹æ°æ®èç¹å
å«ä¸ä¸ª<tt>void</tt> æéç¨æ¥ä¿åè¿ä¸ªèç¹å·²ç»åé
çèªå®ä¹æ°æ®ï¼è¿æä¸ä¸ªæåéæ¯å½æ°çæéç¨äºå½èç¹è¢«å é¤æ¶éæ¾èªå®ä¹æ°æ®ã</p>
<p>ä¿ååè°æ¥æ¶ä¸ä¸ªèç¹æé并ä¸è¿åä¸ä¸ªå
å«èªå®ä¹æ°æ®å¼çå·²ç»åé
çå符串ãä¸é¢çä¿ååè°å½æ°å¯ä»¥è¢«ç¨æ¥ä¿åæ们çISOæ¥æ/æ¶é´ç±»åï¼</p>
<pre> char *
save_custom(mxml_node_t *node)
{
char data[255];
iso_date_time_t *dt;
dt = (iso_date_time_t *)node->custom.data;
snprintf(data, sizeof(data),
"%04u-%02u-%02uT%02u:%02u:%02uZ",
dt->year, dt->month, dt->day,
dt->hour, dt->minute, dt->second);
return (strdup(data));
}
</pre>
<p>ä½ å¯ä»¥æ³¨åè¿äºåè°å½æ°ä½¿ç¨<a href="#mxmlSetCustomHandlers">
<tt>mxmlSetCustomHandlers()</tt></a> å½æ°ï¼</p>
<pre> mxmlSetCustomHandlers(<b>load_custom</b>,<b>save_custom</b>);
</pre>
<!-- NEED 20 -->
<h2><a name="4_4">æ¹åèç¹çå¼</a></h2>
<p>å°ç°å¨ä¸ºæ¢ææçä¾åéä¸æè¿°äºå¦ä½å建åå è½½æ°çXMLæ°æ®èç¹ãç¶èï¼è®¸å¤çåºç¨ç¨åºå¨å®ä»¬çå·¥ä½ä¸éè¦æ纵æè
æ¹åèç¹ï¼æ以Mini-XMLæä¾äºä¸äºå½æ°æ¥å®å
¨çæ¹åèç¹çå¼å¹¶ä¸ä¸ä¼åçå
åæ³æ¼ã</p>
<p>å·²æçèç¹å¯ä»¥è¢«æ¹åéè¿ä½¿ç¨å½æ°<a href="#mxmlSetElement"><tt>
mxmlSetElement()</tt></a>, <a href="#mxmlSetInteger"><tt>
mxmlSetInteger()</tt></a>, <a href="#mxmlSetOpaque"><tt>mxmlSetOpaque()</tt>
</a>, <a href="#mxmlSetReal"><tt>mxmlSetReal()</tt></a>, <a href="#mxmlSetText">
<tt>mxmlSetText()</tt></a>, å <a href="#mxmlSetTextf"><tt>
mxmlSetTextf()</tt></a>ãä¾å¦ï¼ä½¿ç¨ä¸é¢çå½æ°è°ç¨å¯ä»¥æ¹åä¸ä¸ªææ¬èç¹å°å
å«å符串"new"并ä¸å
·æå导ç空ç½å符ï¼</p>
<pre> mxml_node_t *node;
mxmlSetText(node, 1, "new");
</pre>
<h2><a name="4_5">æ ¼å¼åçææ¬</a></h2>
<p><a href="#mxmlNewTextf"><tt>mxmlNewTextf()</tt></a>å<a href="#mxmlSetTextf">
<tt>mxmlSetTextf()</tt></a> å½æ°åå«æ¯å建åæ¹åææ¬èç¹ï¼ä½¿ç¨<tt>printf</tt>-é£æ ¼çæ ¼å¼å符串ååæ°ãä¾å¦ï¼ä½¿ç¨ä¸é¢çå½æ°è°ç¨æ¥å建ä¸ä¸ªæ°çææ¬èç¹å
å«ä¸ä¸ªæé çæ件åï¼
</p>
<pre> mxml_node_t *node;
node = mxmlNewTextf(node, 1, "%s/%s",
path, filename);
</pre>
<h2><a name="4_6">ç´¢å¼</a></h2>
<p>Mini-XML æä¾äºä¸äºå½æ°æ¥ç®¡çèç¹çç´¢å¼ãå½åçå®ç°æä¾äºåæ ·çåè½å°±å <a href="#mxmlFindElement">
<tt>mxmlFindElement()</tt></a>ä¸æ ·ã使ç¨ç´¢å¼ä¼å¿æ¯å¯ä»¥ä½¿æç´¢åæ举XMLå
ç´ æ¾èå å¿«ãå¯ä¸ä¸å©çæ¯æ¯ä¸ªç´¢å¼é½æ¯ä¸ä¸ªå
³äºè¿ä¸ªXMLææ¡£çéæå¿«ç
§ï¼æ以索å¼ä¸éåå½ç¸å¯¹äºå®çæç´¢æä½ï¼XMLæ°æ®æ´å é¢ç¹æ´æ°æ¶çæ
åµãä¸é¢çå建ä¸ä¸ªç´¢å¼è¿ä¼¼ç¸å½äºéåè¿ä¸ªXMLææ¡£æ ãå¨ç´¢å¼ä¸çèç¹è¢«æç
§XMLå
ç´ ååå®çåæ°å¼è¿è¡æåºã</p>
<p>è¿äºç´¢å¼è¢«ä¿åå¨<a href="#mxml_index_t"><tt>mxml_index_t</tt></a>
ç»æä¸ãç¨<a href="#mxmlIndexNew"><tt>mxmlIndexNew()</tt></a>å½æ°å¯ä»¥å建ä¸ä¸ªæ°çç´¢å¼ï¼</p>
<pre> mxml_node_t *tree;
mxml_index_t *ind;
ind = mxmlIndexNew(tree, "element",
"attribute");
</pre>
<p>第ä¸ä¸ªåæ°æ¯éè¦è¿è¡ç´¢å¼çXMLèç¹æ ãé常æ¯ä¸ä¸ªæå<tt>?xml</tt>å
ç´ çèç¹ã</p>
<p>第äºä¸ªåæ°å
å«äºéè¦è¿è¡ç´¢å¼çXMLå
ç´ ï¼ä½¿ç¨<tt>NULL</tt>å¼å°æç
§åæ¯é¡ºåºç´¢å¼ææçXMLå
ç´ èç¹ã</p>
<p>第ä¸ä¸ªåæ°å
å«äºéè¦è¿è¡ç´¢å¼çå±æ§ï¼ä½¿ç¨<tt>NULL</tt>å°ä½¿åªæXMLå
ç´ åå被索å¼ã</p>
<p>å½ç´¢å¼è¢«å»ºç«åï¼å½æ°<a href="#mxmlIndexEnum"><tt>
mxmlIndexEnum()</tt></a>, <a href="#mxmlIndexFind"><tt>mxmlIndexFind()</tt>
</a>, and <a href="#mxmlIndexReset"><tt>mxmlIndexReset()</tt></a>å¯ä»¥è¢«ç¨æ¥è®¿é®ç´¢å¼ä¸çèç¹ã
å½æ°<a href="#mxmlIndexReset">
<tt>mxmlIndexReset()</tt></a>被ç¨æ¥éç½®å¨ç´¢å¼ä¸ç"å½å"èç¹æéï¼å
è®¸ä½ å¨åä¸ä¸ªç´¢å¼ä¸è¿è¡æ°çæç´¢åæ举éåãå
¸ååºç¨æ¯ä½ å°å¨ä½ è°ç¨å½æ°<a href="#mxmlIndexEnum"><tt>mxmlIndexEnum()</tt></a> å<a href="#mxmlIndexFind">
<tt>mxmlIndexFind()</tt></a>ä¹åè°ç¨è¿ä¸ªå½æ°ã</p>
<p>å½æ°<a href="#mxmlIndexEnum"><tt>mxmlIndexEnum()</tt></a> ç¨æ¥æ举å¨ç´¢å¼ä¸çæ¯ä¸ä¸ªèç¹ï¼å¯ä»¥å¨ä¸ä¸ªå¾ªç¯ä¸ä½¿ç¨ï¼å¦ä¸æ示ï¼</p>
<pre> mxml_node_t *node;
mxmlIndexReset(ind);
while ((node = mxmlIndexEnum(ind)) != NULL)
{
// do something with node
}
</pre>
<p>å½æ°<a href="#mxmlIndexFind"><tt>mxmlIndexFind()</tt></a> å®ä½ä¸ä¸æ¬¡å¨ç´¢å¼ä¸åºç°çXMLå
ç´ ååå±æ§å¼ãå®å¯ä»¥è¢«ç¨äºåç°å¨ç´¢å¼ä¸çææå¹é
çXMLå
ç´ ï¼å¦ä¸æ示ï¼</p>
<pre> mxml_node_t *node;
mxmlIndexReset(ind);
while ((node = mxmlIndexFind(ind, "element",
"attr-value"))
!= NULL)
{
// do something with node
}
</pre>
<p>第äºå第ä¸ä¸ªåæ°åå«è¡¨ç¤ºXMLå
ç´ ååå±æ§å¼ãä½¿ç¨ <tt>NULL</tt>æéç¨æ¥è¿åç´¢å¼ä¸ææçXMLå
ç´ æè
å±æ§ãå¦æXMLå
ç´ ååå±æ§å¼åæ¶ä¸º<tt>NULL</tt>åç¸å½äºè°ç¨å½æ°<tt>
mxmlIndexEnum</tt>ã</p>
<p>å½æ们使ç¨å®è¿ä¸ªç´¢å¼åï¼ä½¿ç¨å½æ°<a href="#mxmlIndexDelete%28%29">
<tt>mxmlIndexDelete()</tt></a> æ¥å é¤å®:</p>
<pre> mxmlIndexDelete(ind);
Mini-XMLæ¯æä¸ä¸ªå ³äºç®åXML API (SAX)çå®ç°ï¼ä»¥å è®¸ä½ éè¿èç¹æµçæ¹å¼å è½½åå¤çXMLææ¡£ãå¦å¤å è®¸ä½ å¤çä»»ä½å¤§å°çXMLæ件ï¼Mini-XMLçå®ç°ä¹å è®¸ä½ ä¸ºä¸ä¸æ¥çå¤çèåªå¨å åä¸ä¿çXMLææ¡£çä¸é¨åã
The mxmlSAXLoadFd, mxmlSAXLoadFile, å mxmlSAXLoadString å½æ°æä¾äºSAXå è½½çAPIãæ¯ä¸ªå½æ°å·¥ä½èµ·æ¥å°±è±¡ mxmlLoad å½æ°ä¸æ ·ï¼ä½æ¯ä½¿ç¨ä¸ä¸ªåè°å½æ°æ¥å¤çå®è¯»å°çæ¯ä¸ä¸ªèç¹ã
åè°å½æ°æ¥æ¶å°ä¸ä¸ªèç¹ï¼ä¸ä¸ªäºä»¶ä»£ç åä¸ä¸ªä½ æä¾çç¨æ·æ°æ®æéï¼
void sax_cb(mxml_node_t *node, mxml_sax_event_t event, void *data) { ... do something ... }
äºä»¶(event)å°æ¯ä¸é¢çå ¶ä¸ä¸ä¸ªï¼
XMLå ç´ å°è¢« éæ¾ å¨ä¸ä¸ª"å ³é"å ç´ è¢«å¤çåãææå ¶ä»çèç¹å¨ä»ä»¬è¢«å¤çåé½è¢«éæ¾ãSAXåè°å½æ°å¯ä»¥ ä¿ç è¿ä¸ªèç¹ï¼éè¿è°ç¨å½æ° mxmlRetain ãä¾å¦ï¼ä¸é¢çSAXåè°å½æ°å°ä¿çææçèç¹ï¼å°±åä¸ä¸ªæ®éçå åå è½½ä¸æ ·ï¼
void sax_cb(mxml_node_t *node, mxml_sax_event_t event, void *data) { if (event != MXML_SAX_ELEMENT_CLOSE) mxmlRetain(node); }
æ´å¤çå ¸åSAXåè°å½æ°å°åªä¿çåé¢éè¦å¤ççè¿ä¸ªXMLææ¡£çä¸å°é¨åãä¾å¦ï¼ä¸é¢çSAXåè°å½æ°å°ä¿çä¸ä¸ªXHTMLæ件çæ é¢å头é¨ä¿¡æ¯ãå®æ»æ¯ä¿çä¸ä¸ªXMLå ç´ ï¼ç¶èç¹ï¼å°±å<html>, <head>, å <body>,并å¤çæ令èç¹å°±å <?xml ... ?> å<!DOCTYPE ... >ï¼
void sax_cb(mxml_node_t *node, mxml_sax_event_t event, void *data) { if (event == MXML_SAX_ELEMENT_OPEN) { /* * ä¿çæ é¢åå¤´é¨ */ char *name = node->value.element.name; if (!strcmp(name, "html") || !strcmp(name, "head") || !strcmp(name, "title") || !strcmp(name, "body") || !strcmp(name, "h1") || !strcmp(name, "h2") || !strcmp(name, "h3") || !strcmp(name, "h4") || !strcmp(name, "h5") || !strcmp(name, "h6")) mxmlRetain(node); } else if (event == MXML_SAX_DIRECTIVE) mxmlRetain(node); else if (event == MXML_SAX_DATA && node->parent->ref_count > 1) { /* * å¦æç¶èç¹è¢«ä¿çï¼é£ä¹è¿ä¸ªæ°æ®èç¹æ好æ¯ä¹è¢«ä¿çã */ mxmlRetain(node); } }
è¿ä¸ªç»ææ¡æ¶ææ¡£æ å¯ä»¥è¢«æç´ å°±åä¸ä¸ªä½¿ç¨å½æ°mxmlLoad å è½½çä¸æ ·ãä¾å¦ï¼ä¸ä¸ªè¿æ»¤å¨ç¨åºç¨æ¥ä»æ åè¾å ¥(stdin)ä¸è¯»åä¸ä¸ªXHTMLææ¡£ï¼å¹¶æ¾ç¤ºå¨ææ¡£ä¸çæ é¢åæ 头ï¼å¦ä¸æ示ï¼
mxml_node_t *doc, *title, *body, *heading; doc = mxmlSAXLoadFd(NULL, 0, MXML_TEXT_CALLBACK, sax_cb, NULL); title = mxmlFindElement(doc, doc, "title", NULL, NULL, MXML_DESCEND); if (title) print_children(title); body = mxmlFindElement(doc, doc, "body", NULL, NULL, MXML_DESCEND); if (body) { for (heading = body->child; heading; heading = heading->next) print_children(heading); }
è¿ä¸ç« æè¿°äºå¦ä½ä½¿ç¨mxmldoc(1) ç¨åºèªå¨ä»cåc++æºæ件ä¸çæææ¡£ã
æåå¼åæ¯ç¨æ¥çæMini-XML åCUPS APIçææ¡£ï¼ç°å¨mxmldocæ¯ä¸ä¸ªéç¨å·¥å ·å®ç°äºæ«æCåC++æºæ件以çæHTMLåmanæå页ææ¡£ä¸ä¸ä¸ªæè¿°è¿äºæºæ件ä¸çå½æ°ãç±»ååå®çå®ä¹çXMLæ件ãä¸åä¸äºæµè¡çææ¡£çæå·¥å ·å¦Doxygen æ Javadoc, mxmldoc使ç¨"å¨çº¿"注é并ä¸æ¯æ³¨é头æ件ï¼å 许æ´å èªç¶ç代ç ææ¡£ã
缺çæ åµä¸ï¼mxmldoc çæHTMLæ档个ï¼ä¾å¦ï¼ä¸é¢çå½ä»¤å°æ«æææçå¨å½åç®å½ä¸çCæºä»£ç å头æ件并çæä¸ä¸ªHTMLææ¡£æä»¶å« filename.html:
mxmldoc *.h *.c >filename.html ENTER
ä½ ä¹å¯ä»¥æå®å建ä¸ä¸ªå å«æææºæ件信æ¯çXMLæ件ãä¾å¦ï¼ä¸é¢çå½ä»¤å建ä¸ä¸ªXMLæ件 filename.xml并添å å°è¿ä¸ªHTMLæ件ä¸ï¼
mxmldoc filename.xml *.h *.c >filename.html ENTER
--no-output éé¡¹å ³éæ åçHTMLè¾åºï¼
mxmldoc --no-output filename.xml *.h *.c ENTER
ä½ å¯ä»¥å次è¿è¡mxmldocéè¿è¿ä¸ªXMLæ件æ¥çæHTMLææ¡£ï¼
mxmldoc filename.xml >filename.html ENTER
--man filename é项æ¥åè¯mxmldocå建ä¸ä¸ªæå页(man page)代æ¿HTMLææ¡£ï¼ä¾å¦ï¼
mxmldoc --man filename filename.xml \ >filename.man ENTER mxmldoc --man filename *.h *.c \ >filename.man ENTER mxmldoc --man filename filename.xml *.h *.c \ >filename.man ENTER
å¨ä¸é¢å·²ç»æå°ï¼mxmldoc æ¥çå¨çº¿æ³¨éæ¥æè¿°ä½ æºæ件ä¸çå½æ°ãç±»å以å常éãMxmldoc å°ä¸ºä½ æºæ件ä¸"ææ"å ¬å¼çå½åçæææ¡£ï¼ææ以ä¸å线å¼å§çå称å被使ç¨@private@ æ令注解çå称被认为æ¯âç§æâçèä¸çæææ¡£ã
åºç°å¨å½æ°æè ç±»åå®ä¹åé¢ç注é被ç¨æ¥çåºè¿ä¸ªå½æ°æè ç±»åçææ¡£ãåºç°å¨åæ°ãå®ä¹ãè¿åç±»åæè åéå®ä¹è¢«ç¨æ¥çæå®ä»¬ç注éãä¾å¦ï¼ä¸å代ç çæå®ä¹ä¸ä¸ªå å«key/vaueçç»æ以åä¸ä¸ªå建è¿ä¸ªç»æçæ°å®ä¾çå½æ°ï¼
/* A key/value pair. This is used with the dictionary structure. */ struct keyval { char *key; /* Key string */ char *val; /* Value string */ }; /* Create a new key/value pair. */ struct keyval * /* New key/value pair */ new_keyval( const char *key, /* Key string */ const char *val) /* Value string */ { ... }
Mxmldoc æ»æ¯ç¥é并ä»æ³¨éå符串ä¸ç§»é¤å¤ä½ç(*)å·ï¼æ以ä¸é¢çè¿ä¸ªæ³¨éå符串ï¼
/* * Compute the value of PI. * * The function connects to an Internet server * that streams audio of mathematical monks * chanting the first 100 digits of PI. */
å°è¢«æ¾ç¤ºä¸ºï¼
Compute the value of PI. The function connects to an Internet server that streams audio of mathematical monks chanting the first 100 digits of PI.
注éä¸ä¹å¯ä»¥å å«@name ...@ è¿æ ·çç¹æ®æ令å符串ï¼
Mxmldoc ä¹æä¾äºä¸äºé项æ¥è®¾ç½®çæçææ¡£ä¸çæ é¢ãå段ååç®ä»ãThe --title text é项æå®äºææ¡£çæ é¢ãæ é¢å符串é常æ¾å¨å¼å·å ï¼
mxmldoc filename.xml \ --title "My Famous Documentation" \ >filename.html ENTER
--section name é项æå®äºææ¡£çå段åã对äºHTMLææ¡£ï¼è¿ä¸ªååæ¾å¨ä¸ä¸ªHTML注éåä¸ï¼å¦ä¸æ示ï¼
<!-- SECTION: name -->
对äºæå页(man pages), å段åé常æ¯ä¸ä¸ªæ°å("3")ï¼æè æ¯ä¸ä¸ªæ°ååé¢è·çåååå¦("3acme")ãè¿ä¸ªå段å被使ç¨å¨æå页(man pages)ä¸ç.THæ令éï¼
.TH mylibrary 3acme "My Title" ...
缺çæå页(man pages)çå段åè¾åºæ¯"3"ã对äºHTMLè¾åºæ²¡æ缺ççå段åã
æåï¼--intro filename é项æå®äºä¸ä¸ªæ件æ¥åµå ¥å°å¨æ é¢åå段åä¹ååçæææ¡£çåé¢ã对äºHTMLææ¡£ï¼è¿ä¸ªæä»¶å¿ é¡»å ¼å®¹HTML并ä¸ä¸è½ä½¿ç¨DOCTYPE, html, and bodyå ç´ ã .对äºæå页ææ¡£ï¼è¿ä¸ªæä»¶å¿ é¡»å ¼å®¹ææçnroff(1) ææ¬.
The Mini-XML library and included programs are provided under the terms of the GNU Library General Public License (LGPL) with the following exceptions:
If you link the application to a modified version of Mini-XML, then the changes to Mini-XML must be provided under the terms of the LGPL in sections 1, 2, and 4.
GNU LIBRARY GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1991 Free Software Foundation, Inc.
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
Everyone is permitted to copy and distribute verbatim copies of
this license document, but changing it is not allowed.
[This is the first released version of the library GPL. It is
numbered 2 because it goes with version 2 of the ordinary GPL.]
Preamble
The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users.
This license, the Library General Public License, applies to some specially designated Free Software Foundation software, and to any other libraries whose authors decide to use it. You can use it for your libraries, too.
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library, or if you modify it.
For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link a program with the library, you must provide complete object files to the recipients so that they can relink them with the library, after making changes to the library and recompiling it. And you must show them these terms so they know their rights.
Our method of protecting your rights has two steps: (1) copyright the library, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the library.
Also, for each distributor's protection, we want to make certain that everyone understands that there is no warranty for this free library. If the library is modified by someone else and passed on, we want its recipients to know that what they have is not the original version, so that any problems introduced by others will not reflect on the original authors' reputations.
Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that companies distributing free software will individually obtain patent licenses, thus in effect transforming the program into proprietary software. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.
Most GNU software, including some libraries, is covered by the ordinary GNU General Public License, which was designed for utility programs. This license, the GNU Library General Public License, applies to certain designated libraries. This license is quite different from the ordinary one; be sure to read it in full, and don't assume that anything in it is the same as in the ordinary license.
The reason we have a separate public license for some libraries is that they blur the distinction we usually make between modifying or adding to a program and simply using it. Linking a program with a library, without changing the library, is in some sense simply using the library, and is analogous to running a utility program or application program. However, in a textual and legal sense, the linked executable is a combined work, a derivative of the original library, and the ordinary General Public License treats it as such.
Because of this blurred distinction, using the ordinary General Public License for libraries did not effectively promote software sharing, because most developers did not use the libraries. We concluded that weaker conditions might promote sharing better.
However, unrestricted linking of non-free programs would deprive the users of those programs of all benefit from the free status of the libraries themselves. This Library General Public License is intended to permit developers of non-free programs to use free libraries, while preserving your freedom as a user of such programs to change the free libraries that are incorporated in them. (We have not seen how to achieve this as regards changes in header files, but we have achieved it as regards changes in the actual functions of the Library.) The hope is that this will lead to faster development of free libraries.
The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the libary" and a "work that uses the library". The former contains code derived from the library, while the latter only works together with the library.
Note that it is possible for a library to be covered by the ordinary General Public License rather than by this special one.
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Library General Public License (also called "this License"). Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library.
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library.
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful.
(For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.)
These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library.
In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices.
Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange.
If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also compile or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things:
b) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution.
c) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place.
d) Verify that the user has already received a copy of these materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute.
7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things:
b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.
11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
13. The Free Software Foundation may publish revised and/or new versions of the Library General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License).
To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
one line to give the library's name and an idea of what it does.
Copyright (C) year name of author
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker.
signature of Ty Coon, 1 April 1990 Ty Coon, President of Vice
That's all there is to it!
æ·»å ä¸ä¸ªèç¹å°æ ä¸
void mxmlAdd (
mxml_node_t *parent,
int where,
mxml_node_t *child,
mxml_node_t *node
);
æ·»å ä¸ä¸ªæå®çèç¹å°ç¶èç¹ï¼å¦æchildåæ°ä¸æ¯NULLï¼å°è¿ä¸ªæ°çèç¹æ·»å å°æå®ç"child"çåé¢æè åé¢ï¼ç±whereåæ°å³å®ï¼ãå¦æchildåæ°æ¯NULLï¼ææ°èç¹æ·»å å°åèç¹å表çæåé¢(MXML_ADD_BEFORE)æè æ¶åèç¹å表çæåé¢(MXML_ADD_AFTER)ã常éMXML_ADD_TO_PARENT å¯ä»¥è¢«ç¨æ¥æå®ä¸ä¸ªNULLçchildæéã
å é¤ä¸ä¸ªèç¹åå®çææçåèç¹ã
void mxmlDelete (
mxml_node_t *node
);
å¦æè¿ä¸ªæå®çèç¹æä¸ä¸ªç¶èç¹ï¼è¿ä¸ªå½æ°é¦å 使ç¨mxmlRemove() å½æ°ä»å®çç¶èç¹ä¸ç§»é¤èªå·±ã
å é¤ä¸ä¸ªåæ°
void mxmlElementDeleteAttr (
mxml_node_t *node,
const char *name
);
è·åä¸ä¸ªåæ°
const char *mxmlElementGetAttr (
mxml_node_t *node,
const char *name
);
å±æ§å¼æè NULL
å¦ænodeåæ°ä¸æ¯ä¸ä¸ªXMLå ç´ æè æå®çå±æ§åä¸åå¨åè¿åNULLã
设置ä¸ä¸ªå±æ§ã
void mxmlElementSetAttr (
mxml_node_t *node,
const char *name,
const char *value
);
å¦æè¿ä¸ªå±æ§åå·²ç»åå¨ï¼è¿ä¸ªå±æ§çå¼å°è¢«æ¿æ¢ä¸ºæ°çå符串å¼ãè¿ä¸ªå符串å¼å°è¢«æ·è´å°è¿ä¸ªXMLå ç´ èç¹ï¼å¦æè¿ä¸ªèç¹ä¸æ¯ä¸ä¸ªXMLå ç´ ï¼åè¿ä¸ªå½æ°ä¸åä»»ä½äºã
设置ä¸ä¸ªXMLå ç´ å±æ§ä½¿ç¨ä¸ä¸ªæ ¼å¼åçå¼ã
void mxmlElementSetAttrf (
mxml_node_t *node,
const char *name,
const char *format,
...
);
å¦æè¿ä¸ªå±æ§åå·²ç»åå¨ï¼è¿ä¸ªå±æ§çå¼å°è¢«æ¿æ¢ä¸ºæ°çæ ¼å¼åå符串å¼ãè¿ä¸ªæ ¼å¼ååå符串å¼å°è¢«æ·è´å°è¿ä¸ªXMLå ç´ èç¹ï¼å¦æè¿ä¸ªèç¹ä¸æ¯ä¸ä¸ªXMLå ç´ ï¼åè¿ä¸ªå½æ°ä¸åä»»ä½äºã
æ·»å ä¸ä¸ªåè°å½æ°æ¥å°XMLå®ä½è½¬æ¢ä¸ºUnicodeç¼ç å符ã
int mxmlEntityAddCallback (void);
0 æå, -1 失败
è·åä¸ä¸ªå符å¼å¯¹åºçXMLå®ä½ååã
const char *mxmlEntityGetName (
int val
);
XMLå®ä½ååæè NULL
å¦ævalä¸éè¦è¢«æ è¯ä¸ºä¸ä¸ªå½åçXMLå®ä½ï¼è¿åNULLã
è·åä¸ä¸ªä»£è¡¨å°ä¸ä¸ªXMLå½åå®ä½çå符ã
int mxmlEntityGetValue (
const char *name
);
å符å¼æè -1代表é误
XMLå®ä½ååæ»æ¯å¯ä»¥è¢«å ³èå°ä¸ä¸ªæ°å常éï¼å¦æè¿ä¸ªååæªç¥åè¿å-1ã
å é¤ä¸ä¸ªXMLå®ä½åè°ã
void mxmlEntityRemoveCallback (void);
æç´¢ä¸ä¸ªå½åçXMLå ç´ ã
mxml_node_t *mxmlFindElement
(
mxml_node_t *node,
mxml_node_t *top,
const char *name,
const char *attr,
const char *value,
int descend
);
XMlå ç´ èç¹æè NULL
æç´¢å¯ä»¥è¢«XMLå ç´ åï¼å±æ§ååå±æ§å¼æéå®ï¼ä»»ä½ååæè å¼çäºNULL被å¤çå°±ç¸å½äºéé 符ï¼æ以使ç¨ä¸åçæç´¢æ¹æ³å¯ä»¥è¢«å®ç°ç¨æ¥æ¥çææçæå®å称çXMLå ç´ æè æ¯ææçå ·ææå®å±æ§çXMLå ç´ ãåæ°ï¼ descend ç¡®å®äºæ¯å¦åä¸æç´¢åèç¹ï¼éå¸¸ä½ å°ä½¿ç¨ MXML_DESCEND_FIRSTä½ä¸ºç¬¬ä¸æ¬¡æç´¢ï¼ç¶å使ç¨ä½¿ç¨ MXML_NO_DESCENDæ¥åç°æ´å¤çè¿ä¸ªèç¹çç´æ¥åèç¹ã top èç¹åæ°çº¦æäºæç´¢å¨ä¸ä¸ªæå®èç¹çåèç¹ä¸ã
å é¤ä¸ä¸ªç´¢å¼ã
void mxmlIndexDelete (
mxml_index_t *ind
);
è¿åç´¢å¼ä¸çä¸ä¸ä¸ªèç¹ã
mxml_node_t *mxmlIndexEnum (
mxml_index_t *ind
);
ä¸ä¸ä¸ªèç¹æè NULL代表没ææ´å¤çèç¹
è¿åèç¹é¡ºåºå°æç §ç´¢å¼çæåºè¢«è¿åã
æç´¢ä¸ä¸ä¸ªå¹é çèç¹ã
mxml_node_t *mxmlIndexFind (
mxml_index_t *ind,
const char *element,
const char *value
);
èç¹æè NULL代表没æåç°ã
ä½ å¨ç¬¬ä¸æ¬¡ä½¿ç¨ä¸ä¸ªç¹å®çå å«"element"å"value"å符串çéåæ¥è°ç¨è¿ä¸ªå½æ°ä¹ååºè¯¥é¦å è°ç¨mxmlIndexReset()å½æ°ãå¦æ"element"å"value"åæ¶çäºNULLåç¸å½äºè°ç¨äºmxmlIndexEnum()å½æ°ã
å建ä¸ä¸ªæ°çç´¢å¼ã
mxml_index_t *mxmlIndexNew
(
mxml_node_t *node,
const char *element,
const char *attr
);
æ°çç´¢å¼
被å建çç´¢å¼å°å å«å ·å¤æå®çå ç´ åå/æå±æ§ææçèç¹ãå¦æ"element" å"attr"åæ¶çäºNULLï¼ç´¢å¼å°å å«ä¸ä¸ªè¢«æåºçå®æ´èç¹æ çå表ãèç¹è¢«æç §XMLå ç´ ååéæ©çå±æ§å¼ï¼å¦æ"attr"åæ°ä¸çäºNULLï¼è¿è¡æåºã
é设索å¼ä¸çæ举/æç´¢æé并ä¸è¿åç´¢å¼ä¸ç第ä¸ä¸ªèç¹ã
mxml_node_t *mxmlIndexReset
(
mxml_index_t *ind
);
第ä¸ä¸ªèç¹æè NULL代表索å¼ä¸ºç©ºã
è¿ä¸ªå½æ°éè¦è¢«é¦å è°ç¨ï¼å¨ç¬¬ä¸æ¬¡ä½¿ç¨å½æ°mxmlIndexEnum() æ mxmlIndexFind()ä¹åã
è½½å ¥ä¸ä¸ªæ件æ述符å°ä¸ä¸ªXMLèç¹æ ã
mxml_node_t *mxmlLoadFd (
mxml_node_t *top,
int fd,
mxml_load_cb_t cb
);
第ä¸ä¸ªèç¹æè NULL代表æ件ä¸è½è¢«è¯»åã
å¨æå®æ件ä¸çææèç¹å°è¢«æ·»å å°ææå®ç顶é¨èç¹ãå¦æ没æ"top"顶é¨èç¹è¢«æä¾ï¼è¿ä¸ªXMLæ件å¿
é¡»æ¯è§èç并ä¸æ´ä¸ªæ件åªæä¸ä¸ªç¶èç¹ä¸º<?xml> ã
åè°å½æ°è¿åçå¼ç±»åå°è¢«ä½¿ç¨å°åèç¹ãå¦æ MXML_NO_CALLBACK åæ°è¢«æå®ï¼é£ä¹ææçåèç¹å°é½ä¼æ¯MXML_ELEMENT æè
MXML_TEXT å
¶ä¸ä¹ä¸çèç¹ã
常é MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK,
MXML_REAL_CALLBACK, å MXML_TEXT_CALLBACK å®ä¹äºå°è½½å
¥æå®ç±»åçåèç¹ã
è½½å ¥ä¸ä¸ªæ件å°ä¸ä¸ªXMLèç¹æ ã
mxml_node_t *mxmlLoadFile (
mxml_node_t *top,
FILE *fp,
mxml_load_cb_t cb
);
第ä¸ä¸ªèç¹æè NULL代表æ件ä¸è½è¢«è¯»åã
å¨æå®æ件ä¸çææèç¹å°è¢«æ·»å å°ææå®ç顶é¨èç¹ãå¦æ没æ"top"顶é¨èç¹è¢«æä¾ï¼è¿ä¸ªXMLæ件å¿
é¡»æ¯è§èç并ä¸æ´ä¸ªæ件åªæä¸ä¸ªç¶èç¹ä¸º<?xml> ã
åè°å½æ°è¿åçå¼ç±»åå°è¢«ä½¿ç¨å°åèç¹ãå¦æ MXML_NO_CALLBACK åæ°è¢«æå®ï¼é£ä¹ææçåèç¹å°é½ä¼æ¯MXML_ELEMENT æè
MXML_TEXT å
¶ä¸ä¹ä¸çèç¹.
常é MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK,
MXML_REAL_CALLBACK, å MXML_TEXT_CALLBACK å®ä¹äºå°è½½å
¥æå®ç±»åçåèç¹ã
è½½å ¥ä¸ä¸ªæ件å°ä¸ä¸ªXMLèç¹æ ã
mxml_node_t *mxmlLoadString
(
mxml_node_t *top,
const char *s,
mxml_load_cb_t cb
);
第ä¸ä¸ªèç¹æè NULL代表å符串ä¸æé误ã
å¨æå®å符串ä¸çææèç¹å°è¢«æ·»å å°ææå®ç顶é¨èç¹ãå¦æ没æ"top"顶é¨èç¹è¢«æä¾ï¼è¿ä¸ªXMLå符串å¿
é¡»æ¯è§èç并ä¸æ´ä¸ªæ件åªæä¸ä¸ªç¶èç¹ä¸º<?xml> ã
åè°å½æ°è¿åçå¼ç±»åå°è¢«ä½¿ç¨å°åèç¹ãå¦æ MXML_NO_CALLBACK åæ°è¢«æå®ï¼é£ä¹ææçåèç¹å°é½ä¼æ¯MXML_ELEMENT æè
MXML_TEXT å
¶ä¸ä¹ä¸çèç¹.
T常é MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK,
MXML_REAL_CALLBACK, å MXML_TEXT_CALLBACK å®ä¹äºå°è½½å
¥æå®ç±»åçåèç¹ã
å建ä¸ä¸ªæ°çCDATA èç¹.
mxml_node_t *mxmlNewCDATA (
mxml_node_t *parent,
const char *data
);
æ°çèç¹
æ°çCDATAèç¹å°è¢«æ·»å å°æå®ç¶èç¹çåèç¹å表çæåï¼å¸¸é MXML_NO_PARENT å¯ä»¥è¢«ç¨æ¥æå®æ°çCDATAèç¹æ²¡æç¶èç¹ãæ°æ®åç¬¦ä¸²å¿ é¡»æ¯ä»¥ç©ºå符ç»å°¾ï¼å¹¶è¢«æ·è´å°æ°çCDATAèç¹ãCDATAèç¹ä½¿ç¨ MXML_ELEMENT èç¹ç±»åã
å建ä¸ä¸ªæ°çç¨æ·èªå®ä¹æ°æ®èç¹ã
mxml_node_t *mxmlNewCustom (
mxml_node_t *parent,
void *data,
mxml_custom_destroy_cb_t
destroy
);
æ°èç¹
æ°çèªå®ä¹èç¹å°è¢«æ·»å å°æå®ç¶èç¹çåèç¹å表çæåã常é MXML_NO_PARENT å¯ä»¥è¢«ç¨æ¥æå®æ°çèªå®ä¹èç¹æ²¡æç¶èç¹ãNULLå¯ä»¥è¢«éè¿ï¼å½æ°æ®èç¹ä¸æ¯å¨æåé æè æ¯ç¬ç«ç®¡çæ¶ã
å建ä¸ä¸ªæ°çXMLå ç´ èç¹ã
mxml_node_t *mxmlNewElement
(
mxml_node_t *parent,
const char *name
);
æ°èç¹
æ°çXMLå ç´ èç¹å°è¢«æ·»å å°æå®ç¶èç¹çåèç¹å表çæåã常é MXML_NO_PARENT å¯ä»¥è¢«ç¨æ¥æå®æ°çXMLå ç´ èç¹æ²¡æç¶èç¹ã
å建ä¸ä¸ªæ°çæ´æ°èç¹ã
mxml_node_t *mxmlNewInteger
(
mxml_node_t *parent,
int integer
);
æ°èç¹
æ°çæ´æ°èç¹å°è¢«æ·»å å°æå®ç¶èç¹çåèç¹å表çæåã常é MXML_NO_PARENT å¯ä»¥è¢«ç¨æ¥æå®æ°çæ´æ°èç¹æ²¡æç¶èç¹ã
å建ä¸ä¸ªæ°çä¸éæå符串èç¹
mxml_node_t *mxmlNewOpaque (
mxml_node_t *parent,
const char *opaque
);
æ°èç¹
æ°çä¸éæå符串èç¹å°è¢«æ·»å å°æå®ç¶èç¹çåèç¹å表çæåã常é MXML_NO_PARENT å¯ä»¥è¢«ç¨æ¥æå®æ°çä¸éæå符串èç¹æ²¡æç¶èç¹ãè¿ä¸ªåç¬¦ä¸²å¿ é¡»æ¯ç©ºå符ç»å°¾å¹¶è¢«æ·è´å°æ°èç¹ã
å建ä¸ä¸ªæ°çæµ®ç¹æ°èç¹ã
mxml_node_t *mxmlNewReal (
mxml_node_t *parent,
double real
);
æ°èç¹
æ°çæµ®ç¹æ°èç¹å°è¢«æ·»å å°æå®ç¶èç¹çåèç¹å表çæåã常é MXML_NO_PARENT å¯ä»¥è¢«ç¨æ¥æå®æ°çæµ®ç¹æ°èç¹æ²¡æç¶èç¹ã
å建æ°çææ¬å段èç¹ã
mxml_node_t *mxmlNewText (
mxml_node_t *parent,
int whitespace,
const char *string
);
æ°èç¹
æ°çææ¬èç¹å°è¢«æ·»å å°æå®ç¶èç¹çåèç¹å表çæåã常é MXML_NO_PARENT å¯ä»¥è¢«ç¨æ¥æå®æ°çææ¬èç¹æ²¡æç¶èç¹ãåæ°ï¼whitespace被ç¨å¨æå®æ¯å¦å¨è¿ä¸ªèç¹åé¢æåå¯¼ç©ºæ ¼ãææ¬åç¬¦ä¸²å¿ é¡»æ¶ä»¥ç©ºå符ç»å°¾å¹¶è¢«æ·è´å°æ°çèç¹ã
å建ä¸ä¸ªæ°çæ ¼å¼åçææ¬å段èç¹
mxml_node_t *mxmlNewTextf (
mxml_node_t *parent,
int whitespace,
const char *format,
...
);
æ°èç¹
æ°çææ¬èç¹å°è¢«æ·»å å°æå®ç¶èç¹çåèç¹å表çæåã常é MXML_NO_PARENT å¯ä»¥è¢«ç¨æ¥æå®æ°çææ¬èç¹æ²¡æç¶èç¹ãåæ°ï¼whitespace被ç¨å¨æå®æ¯å¦å¨è¿ä¸ªèç¹åé¢æåå¯¼ç©ºæ ¼ãæ ¼å¼ååç¬¦ä¸²å¿ é¡»æ¶ä»¥ç©ºå符ç»å°¾å¹¶è¢«æ ¼å¼åå°æ°çèç¹ã
å建ä¸ä¸ªæ°çXMLææ¡£æ ã
mxml_node_t *mxmlNewXML (
const char *version
);
æ°ç "?xml" èç¹
åæ° "version" æå®äºæ¾å¨"?xml" å ç´ èç¹ä¸ççæ¬å·ãå¦æ为NULLååå®ä¸º "version 1.0"ã
éæ¾ä¸ä¸ªèç¹ã
int mxmlRelease (
mxml_node_t *node
);
æ°çå¼ç¨è®¡æ°
å½å¼ç¨è®¡æ°ä¸º0æ¶ï¼è¿ä¸ªèç¹ï¼ä»¥åææåèç¹ï¼è¢«éè¿å½æ° mxmlDelete() æå é¤ã
移é¤ä¸ä¸ªèç¹ä»å®çç¶èç¹ä¸ã
void mxmlRemove (
mxml_node_t *node
);
ä¸éæ¾èç¹ä½¿ç¨çå åï¼ä½¿ç¨å½æ° mxmlDelete() æ¥éæ¾ãå¦æè¿ä¸ªèç¹æ²¡æç¶èç¹åè¿ä¸ªå½æ°ä¸åä»»ä½äºã
ä¿çä¸ä¸ªèç¹
int mxmlRetain (
mxml_node_t *node
);
æ°çå¼ç¨è®¡æ°
使ç¨SAXåè°ä»ä¸ä¸ªæ件æ述符ä¸å è½½æ°æ®å°ä¸ä¸ªXMLèç¹æ ã
mxml_node_t *mxmlSAXLoadFd (
mxml_node_t *top,
int fd,
mxml_load_cb_t cb,
mxml_sax_cb_t sax_cb,
void *sax_data
);
第ä¸ä¸ªèç¹æè NULL 代表æ件ä¸è½è¢«è¯»åã
å¨æå®æ件ä¸çèç¹å°è¢«æ·»å å°æå®ç顶级èç¹ä¸ãå¦æ"top"èç¹æ²¡ææä¾ï¼è¿ä¸ªXMLæ件å¿
é¡»æ¯è§èç并ä¸æ´ä¸ªæ件åªæä¸ä¸ªç¶èç¹ä¸º<?xml> ãåè°å½æ°"cb"è¿ååèç¹çå¼ç±»åãå¦æ MXML_NO_CALLBACK åæ°è¢«æå®ï¼é£ä¹ææçåèç¹å°é½ä¼æ¯MXML_ELEMENT æè
MXML_TEXT å
¶ä¸ä¹ä¸çèç¹ã
常é MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK,
MXML_REAL_CALLBACK, åMXML_TEXT_CALLBACK 被å®ä¹ç¨äºå è½½æå®ç±»åçåèç¹ã
å¨SAX åè°å½æ°ä¸("sax_cb")ï¼å¯¹äºææèç¹é½å¿
é¡»è°ç¨mxmlRetain()å½æ°ç¨äºä¿ç为以å使ç¨ãå¦åï¼èç¹å°å¨ç¶èç¹è¢«å
³éæ¶æè
å°è¾¾æ°æ®ã注éãCDATAåæ令èç¹æ¶è¢«å é¤ã
使ç¨SAXåè°ä»ä¸ä¸ªæ件ä¸å è½½æ°æ®å°ä¸ä¸ªXMLèç¹æ ã
mxml_node_t *mxmlSAXLoadFile
(
mxml_node_t *top,
FILE *fp,
mxml_load_cb_t cb,
mxml_sax_cb_t sax_cb,
void *sax_data
);
第ä¸ä¸ªèç¹æè NULL 代表æ件ä¸è½è¢«è¯»åã
å¨æå®æ件ä¸çèç¹å°è¢«æ·»å å°æå®ç顶级èç¹ä¸ãå¦æ"top"èç¹æ²¡ææä¾ï¼è¿ä¸ªXMLæ件å¿
é¡»æ¯è§èç并ä¸æ´ä¸ªæ件åªæä¸ä¸ªç¶èç¹ä¸º<?xml> ãåè°å½æ°"cb"è¿ååèç¹çå¼ç±»åãå¦æ MXML_NO_CALLBACK åæ°è¢«æå®ï¼é£ä¹ææçåèç¹å°é½ä¼æ¯MXML_ELEMENT æè
MXML_TEXT å
¶ä¸ä¹ä¸çèç¹ã
常é MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK,
MXML_REAL_CALLBACK, åMXML_TEXT_CALLBACK 被å®ä¹ç¨äºå è½½æå®ç±»åçåèç¹ã
å¨SAX åè°å½æ°ä¸("sax_cb")ï¼å¯¹äºææèç¹é½å¿
é¡»è°ç¨mxmlRetain()å½æ°ç¨äºä¿ç为以å使ç¨ãå¦åï¼èç¹å°å¨ç¶èç¹è¢«å
³éæ¶æè
å°è¾¾æ°æ®ã注éãCDATAåæ令èç¹æ¶è¢«å é¤ã
使ç¨SAXåè°ä»ä¸ä¸ªå符串ä¸å è½½æ°æ®å°ä¸ä¸ªXMLèç¹æ ã
mxml_node_t
*mxmlSAXLoadString (
mxml_node_t *top,
const char *s,
mxml_load_cb_t cb,
mxml_sax_cb_t sax_cb,
void *sax_data
);
第ä¸ä¸ªèç¹æè NULL 代表æ件ä¸è½è¢«è¯»åã
å¨æå®å符串ä¸çèç¹å°è¢«æ·»å å°æå®ç顶级èç¹ä¸ãå¦æ"top"èç¹æ²¡ææä¾ï¼è¿ä¸ªXMLå符串å¿
é¡»æ¯è§èç并ä¸æ´ä¸ªæ件åªæä¸ä¸ªç¶èç¹ä¸º<?xml> ãåè°å½æ°"cb"è¿ååèç¹çå¼ç±»åãå¦æ MXML_NO_CALLBACK åæ°è¢«æå®ï¼é£ä¹ææçåèç¹å°é½ä¼æ¯MXML_ELEMENT æè
MXML_TEXT å
¶ä¸ä¹ä¸çèç¹ã
常é MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK,
MXML_REAL_CALLBACK, åMXML_TEXT_CALLBACK 被å®ä¹ç¨äºå è½½æå®ç±»åçåèç¹ã
å¨SAX åè°å½æ°ä¸("sax_cb")ï¼å¯¹äºææèç¹é½å¿
é¡»è°ç¨mxmlRetain()å½æ°ç¨äºä¿ç为以å使ç¨ãå¦åï¼èç¹å°å¨ç¶èç¹è¢«å
³éæ¶æè
å°è¾¾æ°æ®ã注éãCDATAåæ令èç¹æ¶è¢«å é¤ã
ä¿åä¸ä¸ªXMLèç¹æ å°ä¸ä¸ªå é¨åé çå符串ã
char *mxmlSaveAllocString (
mxml_node_t *node,
mxml_save_cb_t cb
);
åé çå符串æè NULL
è¿ä¸ªå½æ°è¿åä¸ä¸ªæåå符串çæéå
å«äºæè¿°æ´ä¸ªXMLèç¹æ çææ¬ãå½ä½ 使ç¨å®è¿ä¸ªå符串åéè¦ä½¿ç¨free()å½æ°æ¥éæ¾ãå¦æè¿ä¸ªèç¹äº§çäºä¸ä¸ªç©ºå符æè
å符串åé
失败å°è¿åNULLã
åè°å½æ°åæ°æå®äºä¸ä¸ªå½æ°ç¨æ¥å¨æ¯ä¸ªXMLå
ç´ ä¹åæè
ä¹åè¿åä¸ä¸ªç©ºç½å符串æè
NULLãå¦ææå®äºMXML_NO_CALLBACKï¼ç©ºæ ¼å°ä»
被添å å°å
·æåå¯¼ç©ºæ ¼çMXML_TEXTèç¹åé¢ï¼node->value->text->whitespace = 1ï¼åå¨ä¸ä¸ªæå¼XMLå
ç´ æ ç¾çå±æ§å称åé¢ã
ä¿åä¸ä¸ªXMLèç¹æ å°ä¸ä¸ªæ件æ述符ã
int mxmlSaveFd (
mxml_node_t *node,
int fd,
mxml_save_cb_t cb
);
æåè¿å 0ï¼é误è¿å -1ã
åè°å½æ°åæ°æå®äºä¸ä¸ªå½æ°ç¨æ¥å¨æ¯ä¸ªXMLå ç´ ä¹åæè ä¹åè¿åä¸ä¸ªç©ºç½å符串æè NULLãå¦ææå®äºMXML_NO_CALLBACKï¼ç©ºæ ¼å°ä» 被添å å°å ·æåå¯¼ç©ºæ ¼çMXML_TEXTèç¹åé¢ï¼node->value->text->whitespace = 1ï¼åå¨ä¸ä¸ªæå¼XMLå ç´ æ ç¾çå±æ§å称åé¢ã
ä¿åä¸ä¸ªXMLèç¹æ å°ä¸ä¸ªæ件ã
int mxmlSaveFile (
mxml_node_t *node,
FILE *fp,
mxml_save_cb_t cb
);
æåè¿å 0ï¼é误è¿å -1ã
åè°å½æ°åæ°æå®äºä¸ä¸ªå½æ°ç¨æ¥å¨æ¯ä¸ªXMLå ç´ ä¹åæè ä¹åè¿åä¸ä¸ªç©ºç½å符串æè NULLãå¦ææå®äºMXML_NO_CALLBACKï¼ç©ºæ ¼å°ä» 被添å å°å ·æåå¯¼ç©ºæ ¼çMXML_TEXTèç¹åé¢ï¼node->value->text->whitespace = 1ï¼åå¨ä¸ä¸ªæå¼XMLå ç´ æ ç¾çå±æ§å称åé¢ã
ä¿åä¸ä¸ªXMLèç¹æ å°ä¸ä¸ªå符串ã
int mxmlSaveString (
mxml_node_t *node,
char *buffer,
int bufsize,
mxml_save_cb_t cb
);
å符串大å°
è¿ä¸ªå½æ°è¿åå符串éè¦åèæ»æ°ï¼ä½æ¯æå¤æ·è´(bufsize-1)个å符å°æå®çbufferä¸ã
设置ä¸ä¸ªCDATAå ç´ èç¹çå称ã
int mxmlSetCDATA (
mxml_node_t *node,
const char *data
);
æåè¿å 0ï¼å¤±è´¥è¿å -1ã
å¦æè¿ä¸ªèç¹ä¸æ¯ä¸ä¸ªCDATAèç¹åèç¹ä¸åçæ¹åã
对ä¸ä¸ªç¨æ·èªå®ä¹æ°æ®èç¹è®¾ç½®æ°æ®åéæ¯åè°å½æ°ã
int mxmlSetCustom (
mxml_node_t *node,
void *data,
mxml_custom_destroy_cb_t
destroy
);
æåè¿å 0ï¼å¤±è´¥è¿å -1ã
å¦æè¿ä¸ªèç¹ä¸æ¯ä¸ä¸ªç¨æ·èªå®ä¹èç¹åèç¹ä¸åçæ¹åã
设置对äºèªå®ä¹æ°æ®çå¤çåè°å½æ°ã
void mxmlSetCustomHandlers (
mxml_custom_load_cb_t
load,
mxml_custom_save_cb_t save
);
å è½½åè°å½æ°æ¥æ¶ä¸ä¸ªèç¹æéåæ°æ®å符串ï¼æåæ¶å¿
é¡»è¿å 0ï¼é误æ¶è¿åä¸ä¸ªé0å¼ã
ä¿ååè°å½æ°æ¥æ¶ä¸ä¸ªèç¹æéï¼æåæ¶å¿
é¡»è¿åä¸ä¸ªä½¿ç¨mallocåé
çå符串ï¼é误æ¶è¿åNULLã
设置XMLå ç´ èç¹çååã
int mxmlSetElement (
mxml_node_t *node,
const char *name
);
æåè¿å 0ï¼å¤±è´¥è¿å -1ã
å¦æè¿ä¸ªèç¹ä¸æ¯ä¸ä¸ªXMLå ç´ èç¹åèç¹ä¸åçæ¹åã
设置é误信æ¯åè°å½æ°ã
void mxmlSetErrorCallback (
mxml_error_cb_t cb
);
设置ä¸ä¸ªæ´æ°èç¹çå¼ã
int mxmlSetInteger (
mxml_node_t *node,
int integer
);
æåè¿å 0ï¼å¤±è´¥è¿å -1ã
å¦æè¿ä¸ªèç¹ä¸æ¯ä¸ä¸ªæ´æ°èç¹åèç¹ä¸åçæ¹åã
设置ä¸ä¸ªä¸éæå符串èç¹çå¼ã
int mxmlSetOpaque (
mxml_node_t *node,
const char *opaque
);
æåè¿å 0ï¼å¤±è´¥è¿å -1ã
å¦æè¿ä¸ªèç¹ä¸æ¯ä¸ä¸ªä¸éæå符串èç¹åèç¹ä¸åçæ¹åã
设置ä¸ä¸ªæµ®ç¹æ°èç¹çå¼ã
int mxmlSetReal (
mxml_node_t *node,
double real
);
æåè¿å 0ï¼å¤±è´¥è¿å -1ã
å¦æè¿ä¸ªèç¹ä¸æ¯ä¸ä¸ªæµ®ç¹æ°èç¹åèç¹ä¸åçæ¹åã
设置ä¸ä¸ªææ¬èç¹çå¼ã
int mxmlSetText (
mxml_node_t *node,
int whitespace,
const char *string
);
æåè¿å 0ï¼å¤±è´¥è¿å -1ã
å¦æè¿ä¸ªèç¹ä¸æ¯ä¸ä¸ªææ¬èç¹åèç¹ä¸åçæ¹åã
设置ä¸ä¸ªææ¬èç¹çå¼ä¸ºä¸ä¸ªæ ¼å¼åçå符串ã
int mxmlSetTextf (
mxml_node_t *node,
int whitespace,
const char *format,
...
);
æåè¿å 0ï¼å¤±è´¥è¿å -1ã
å¦æè¿ä¸ªèç¹ä¸æ¯ä¸ä¸ªææ¬èç¹åèç¹ä¸åçæ¹åã
设置å¨ä¿åXMLæ°æ®æ¶çèªå¨æè¡ä½ç½®ã
void mxmlSetWrapMargin (
int column
);
å½"column" is <= 0æ¶åæ¶èªå¨æè¡ã
éåå°XMLæ ä¸çä¸ä¸ä¸ªé»è¾èç¹ã
mxml_node_t *mxmlWalkNext (
mxml_node_t *node,
mxml_node_t *top,
int descend
);
ä¸ä¸ä¸ªèç¹æè NULL
"descend"åæ°æ§å¶ä¸ä¸ä¸ªèç¹æ¯å¦èè第ä¸ä¸ªåèç¹ã"top"åæ°çº¦æäºéåè¿ä¸ªèç¹çææåèç¹ã
éåå°XMLæ ä¸çä¸ä¸ä¸ªé»è¾èç¹ã
mxml_node_t *mxmlWalkPrev (
mxml_node_t *node,
mxml_node_t *top,
int descend
);
ä¸ä¸ä¸ªèç¹æè NULL
"descend"åæ°æ§å¶ä¸ä¸ä¸ªèç¹æ¯å¦èè第ä¸ä¸ªåèç¹ã"top"åæ°çº¦æäºéåè¿ä¸ªèç¹çææåèç¹ã
XMLå ç´ èç¹çå±æ§å¼ã
typedef struct mxml_attr_s mxml_attr_t;
èªå®ä¹æ°æ®éæ¯åè°å½æ°åå
typedef void (*mxml_custom_destroy_cb_t)(void *);
èªå®ä¹æ°æ®å è½½åè°å½æ°åå
typedef int (*mxml_custom_load_cb_t)( mxml_node_t *, const char *);
èªå®ä¹æ°æ®ä¿ååè°å½æ°åå
typedef char *(*mxml_custom_save_cb_t)( mxml_node_t *);
èªå®ä¹XMLç±»åå¼
typedef struct mxml_custom_s mxml_custom_t;
XMLå ç´ å¼
typedef struct mxml_element_s mxml_element_t;
é误åè°å½æ°åå
typedef void (*mxml_error_cb_t)(const char *);
XMLèç¹ç´¢å¼
typedef struct mxml_index_s mxml_index_t;
å è½½åè°å½æ°
typedef mxml_type_t (*mxml_load_cb_t)( mxml_node_t *);
XMLèç¹
typedef struct mxml_node_s mxml_node_t;
ä¿ååè°å½æ°
typedef const char *(*mxml_save_cb_t)( mxml_node_t *, int);
SAX åè°å½æ°
typedef void (*mxml_sax_cb_t)( mxml_node_t *, mxml_sax_event_t, void *);
SAX äºä»¶ç±»å.
typedef enum mxml_sax_event_e mxml_sax_event_t;
XMLææ¬èç¹å¼
typedef struct mxml_text_s mxml_text_t;
XMLèç¹å¼
typedef union mxml_value_u mxml_value_t;
XMLå ç´ çå±æ§å¼
struct mxml_attr_s {
char *name;
char *value;
};
èªå®ä¹XMLèç¹å¼
struct mxml_custom_s {
void *data;
mxml_custom_destroy_cb_t
destroy;
};
XMLå ç´ å¼
struct mxml_element_s {
mxml_attr_t *attrs;
char *name;
int num_attrs;
};
XMLèç¹ç´¢å¼
struct mxml_index_s {
int alloc_nodes;
char *attr;
int cur_node;
mxml_node_t **nodes;
int num_nodes;
};
XML èç¹ã
struct mxml_node_s {
struct mxml_node_s *child;
struct mxml_node_s *last_child;
struct mxml_node_s *next;
struct mxml_node_s *parent;
struct mxml_node_s *prev;
int ref_count;
mxml_type_t type;
void *user_data;
mxml_value_t value;
};
XMLææ¬èç¹å¼
struct mxml_text_s {
char *string;
int whitespace;
};
XMLèç¹å¼ã
union mxml_value_u {
mxml_custom_t custom;
mxml_element_t element;
int integer;
char *opaque;
double real;
mxml_text_t text;
};
SAX äºä»¶ç±»åã
XML èç¹ç±»å
è¿ä¸ªéå½æä¾äºmxmldocç¨åºçæXMLæ件æ¶ä½¿ç¨çXML schemaãè¿ä¸ªschema çå¨çº¿çæ¬åè§ï¼
http://www.easysw.com/~mike/mxmldoc.xsd
<?xml version="1.0"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:annotation> <xsd:documentation xml:lang="en"> Mini-XML 2.3 documentation schema for mxmldoc output. Copyright 2003-2007 by Michael Sweet. </xsd:documentation> </xsd:annotation> <!-- basic element definitions --> <xsd:element name="argument" type="argumentType"/> <xsd:element name="class" type="classType"/> <xsd:element name="constant" type="constantType"/> <xsd:element name="description" type="xsd:string"/> <xsd:element name="enumeration" type="enumerationType"/> <xsd:element name="function" type="functionType"/> <xsd:element name="mxmldoc" type="mxmldocType"/> <xsd:element name="namespace" type="namespaceType"/> <xsd:element name="returnvalue" type="returnvalueType"/> <xsd:element name="seealso" type="identifierList"/> <xsd:element name="struct" type="structType"/> <xsd:element name="typedef" type="typedefType"/> <xsd:element name="type" type="xsd:string"/> <xsd:element name="union" type="unionType"/> <xsd:element name="variable" type="variableType"/> <!-- descriptions of complex elements --> <xsd:complexType name="argumentType"> <xsd:sequence> <xsd:element ref="type" minOccurs="1" maxOccurs="1"/> <xsd:element ref="description" minOccurs="0" maxOccurs="1"/> </xsd:sequence> <xsd:attribute name="default" type="xsd:string" use="optional"/> <xsd:attribute name="name" type="identifier" use="required"/> <xsd:attribute name="direction" type="direction" use="optional" default="I"/> </xsd:complexType> <xsd:complexType name="classType"> <xsd:sequence> <xsd:element ref="description" minOccurs="0" maxOccurs="1"/> <xsd:choice minOccurs="0" maxOccurs="unbounded"> <xsd:element ref="class"/> <xsd:element ref="enumeration"/> <xsd:element ref="function"/> <xsd:element ref="struct"/> <xsd:element ref="typedef"/> <xsd:element ref="union"/> <xsd:element ref="variable"/> </xsd:choice> </xsd:sequence> <xsd:attribute name="name" type="identifier" use="required"/> <xsd:attribute name="parent" type="xsd:string" use="optional"/> </xsd:complexType> <xsd:complexType name="constantType"> <xsd:sequence> <xsd:element ref="description" minOccurs="0" maxOccurs="1"/> </xsd:sequence> <xsd:attribute name="name" type="identifier" use="required"/> </xsd:complexType> <xsd:complexType name="enumerationType"> <xsd:sequence> <xsd:element ref="description" minOccurs="0" maxOccurs="1"/> <xsd:element ref="constant" minOccurs="1" maxOccurs="unbounded"/> </xsd:sequence> <xsd:attribute name="name" type="identifier" use="required"/> </xsd:complexType> <xsd:complexType name="functionType"> <xsd:sequence> <xsd:element ref="returnvalue" minOccurs="0" maxOccurs="1"/> <xsd:element ref="description" minOccurs="0" maxOccurs="1"/> <xsd:element ref="argument" minOccurs="1" maxOccurs="unbounded"/> <xsd:element ref="seealso" minOccurs="0" maxOccurs="1"/> </xsd:sequence> <xsd:attribute name="name" type="identifier" use="required"/> <xsd:attribute name="scope" type="scope" use="optional"/> </xsd:complexType> <xsd:complexType name="mxmldocType"> <xsd:choice minOccurs="0" maxOccurs="unbounded"> <xsd:element ref="class"/> <xsd:element ref="enumeration"/> <xsd:element ref="function"/> <xsd:element ref="namespace"/> <xsd:element ref="struct"/> <xsd:element ref="typedef"/> <xsd:element ref="union"/> <xsd:element ref="variable"/> </xsd:choice> </xsd:complexType> <xsd:complexType name="namespaceType"> <xsd:sequence> <xsd:element ref="description" minOccurs="0" maxOccurs="1"/> <xsd:choice minOccurs="0" maxOccurs="unbounded"> <xsd:element ref="class"/> <xsd:element ref="enumeration"/> <xsd:element ref="function"/> <xsd:element ref="struct"/> <xsd:element ref="typedef"/> <xsd:element ref="union"/> <xsd:element ref="variable"/> </xsd:choice> </xsd:sequence> <xsd:attribute name="name" type="identifier" use="required"/> </xsd:complexType> <xsd:complexType name="returnvalueType"> <xsd:sequence> <xsd:element ref="type" minOccurs="1" maxOccurs="1"/> <xsd:element ref="description" minOccurs="0" maxOccurs="1"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="structType"> <xsd:sequence> <xsd:element ref="description" minOccurs="0" maxOccurs="1"/> <xsd:choice minOccurs="0" maxOccurs="unbounded"> <xsd:element ref="variable"/> <xsd:element ref="function"/> </xsd:choice> </xsd:sequence> <xsd:attribute name="name" type="identifier" use="required"/> </xsd:complexType> <xsd:complexType name="typedefType"> <xsd:sequence> <xsd:element ref="type" minOccurs="1" maxOccurs="1"/> <xsd:element ref="description" minOccurs="0" maxOccurs="1"/> </xsd:sequence> <xsd:attribute name="name" type="identifier" use="required"/> </xsd:complexType> <xsd:complexType name="unionType"> <xsd:sequence> <xsd:element ref="description" minOccurs="0" maxOccurs="1"/> <xsd:element ref="variable" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> <xsd:attribute name="name" type="identifier" use="required"/> </xsd:complexType> <xsd:complexType name="variableType"> <xsd:sequence> <xsd:element ref="type" minOccurs="1" maxOccurs="1"/> <xsd:element ref="description" minOccurs="0" maxOccurs="1"/> </xsd:sequence> <xsd:attribute name="name" type="identifier" use="required"/> </xsd:complexType> <!-- data types --> <xsd:simpleType name="direction"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="I"/> <xsd:enumeration value="O"/> <xsd:enumeration value="IO"/> </xsd:restriction> </xsd:simpleType> <xsd:simpleType name="identifier"> <xsd:restriction base="xsd:string"> <xsd:pattern value="[a-zA-Z_(.]([a-zA-Z_(.,)* 0-9])*"/> </xsd:restriction> </xsd:simpleType> <xsd:simpleType name="identifierList"> <xsd:list itemType="identifier"/> </xsd:simpleType> <xsd:simpleType name="scope"> <xsd:restriction base="xsd:string"> <xsd:enumeration value=""/> <xsd:enumeration value="private"/> <xsd:enumeration value="protected"/> <xsd:enumeration value="public"/> </xsd:restriction> </xsd:simpleType> </xsd:schema>
Version: 2.5 Original reporter:
hi,mini-XML is a beautifully XML parser,it so simply,and enough powerful,program by ANSI C can easy to used for embed system. I like it. I make a translate of the program manual to simplified chinese language,it's a HTML in one file,can place it in this site?
well,nice to you! Z.F