mxml/www/docfiles/LoadingXML.html
2004-06-21 11:00:28 +00:00

75 lines
3.0 KiB
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.0</TITLE>
<META NAME="author" CONTENT="Michael Sweet">
<META NAME="copyright" CONTENT="Copyright 2003-2004">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso-iso-8859-1">
<LINK REL="Start" HREF="index.html">
<LINK REL="Contents" HREF="toc.html">
<LINK REL="Prev" HREF="Nodes.html">
<LINK REL="Next" HREF="SavingXML.html">
<STYLE TYPE="text/css"><!--
BODY { font-family: 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 }
--></STYLE>
</HEAD>
<BODY>
<A HREF="toc.html">Contents</A>
<A HREF="Nodes.html">Previous</A>
<A HREF="SavingXML.html">Next</A>
<HR NOSHADE>
<H2><A NAME="3_3">Loading XML</A></H2>
<P>You load an XML file using the <A href="mxmlLoadFile.html#mxmlLoadFile">
<TT>mxmlLoadFile()</TT></A> function:</P>
<PRE>
FILE *fp;
<A href="mxmlnodet.html#mxml_node_t">mxml_node_t</A> *tree;
fp = fopen(&quot;filename.xml&quot;, &quot;r&quot;);
tree = <A href="mxmlLoadFile.html#mxmlLoadFile">mxmlLoadFile</A>(NULL, fp, MXML_NO_CALLBACK);
fclose(fp);
</PRE>
<P>The first argument specifies an existing XML parent node, if any.
Normally you will pass <TT>NULL</TT> for this argument unless you are
combining multiple XML sources. The XML file must contain a complete
XML document including the <TT>?xml</TT> element if the parent node is <TT>
NULL</TT>.</P>
<P>The second argument specifies the stdio file to read from, as opened
by <TT>fopen()</TT> or <TT>popen()</TT>. You can also use <TT>stdin</TT>
if you are implementing an XML filter program.</P>
<P>The third argument specifies a callback function which returns the
value type of the immediate children for a new element node: <TT>
MXML_INTEGER</TT>, <TT>MXML_OPAQUE</TT>, <TT>MXML_REAL</TT>, or <TT>
MXML_TEXT</TT>. Load callbacks are described in detail in <A href="LoadCallbacks.html#LOAD_CALLBACKS">
Chapter 3</A>. The example code uses the <TT>MXML_NO_CALLBACK</TT>
constant which specifies that all data nodes in the document contain
whitespace-separated text values.</P>
<P>The <A href="mxmlLoadString.html#mxmlLoadString"><TT>mxmlLoadString()</TT>
</A> function loads XML node trees from a string:</P>
<PRE>
char buffer[8192];
<A href="mxmlnodet.html#mxml_node_t">mxml_node_t</A> *tree;
...
tree = <A href="mxmlLoadString.html#mxmlLoadString">mxmlLoadString</A>(NULL, buffer, MXML_NO_CALLBACK);
</PRE>
<P>The first and third arguments are the same as used for <TT>
mxmlLoadFile()</TT>. The second argument specifies the string or
character buffer to load and must be a complete XML document including
the <TT>?xml</TT> element if the parent node is <TT>NULL</TT>.</P>
<HR NOSHADE>
<A HREF="toc.html">Contents</A>
<A HREF="Nodes.html">Previous</A>
<A HREF="SavingXML.html">Next</A>
</BODY>
</HTML>