You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.9 KiB
76 lines
2.9 KiB
<!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.3</TITLE>
|
|
<META NAME="author" CONTENT="Michael R. Sweet">
|
|
<META NAME="copyright" CONTENT="Copyright 2003-2007">
|
|
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso-iso-8859-1">
|
|
<LINK REL="Start" HREF="index.html">
|
|
<LINK REL="Contents" HREF="index.html">
|
|
<LINK REL="Prev" HREF="LoadingXML.html">
|
|
<LINK REL="Next" HREF="ControllingLineWrapping.html">
|
|
<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>
|
|
<A HREF="index.html">Contents</A>
|
|
<A HREF="LoadingXML.html">Previous</A>
|
|
<A HREF="ControllingLineWrapping.html">Next</A>
|
|
<HR NOSHADE>
|
|
<H2><A NAME="3_5">Saving XML</A></H2>
|
|
<P>You save an XML file using the <A href="mxmlSaveFile.html#mxmlSaveFile">
|
|
<TT>mxmlSaveFile</TT></A> function:</P>
|
|
<PRE>
|
|
FILE *fp;
|
|
mxml_node_t *tree;
|
|
|
|
fp = fopen("filename.xml", "w");
|
|
mxmlSaveFile(tree, fp, MXML_NO_CALLBACK);
|
|
fclose(fp);
|
|
</PRE>
|
|
<P>The first argument is the XML node tree to save. It should normally
|
|
be a pointer to the top-level <TT>?xml</TT> node in your XML document.</P>
|
|
<P>The second argument is the stdio file to write to, as opened by <TT>
|
|
fopen()</TT> or <TT>popen()</TT>. You can also use <TT>stdout</TT> if
|
|
you are implementing an XML filter program.</P>
|
|
<P>The third argument is the whitespace callback to use when saving the
|
|
file. Whitespace callbacks are covered in detail in <A href="SAVE_CALLBACKS">
|
|
Chapter 3</A>. The previous example code uses the <TT>MXML_NO_CALLBACK</TT>
|
|
constant to specify that no special whitespace handling is required.</P>
|
|
<P>The <A href="mxmlSaveAllocString.html#mxmlSaveAllocString"><TT>
|
|
mxmlSaveAllocString</TT></A>, and <A href="mxmlSaveString.html#mxmlSaveString">
|
|
<TT>mxmlSaveString</TT></A> functions save XML node trees to strings:</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>The first and last arguments are the same as used for <TT>
|
|
mxmlSaveFile()</TT>. The <TT>mxmlSaveString</TT> function takes pointer
|
|
and size arguments for saving the XML document to a fixed-size buffer,
|
|
while <TT>mxmlSaveAllocString()</TT> returns a string buffer that was
|
|
allocated using <TT>malloc()</TT>.</P>
|
|
<HR NOSHADE>
|
|
<A HREF="index.html">Contents</A>
|
|
<A HREF="LoadingXML.html">Previous</A>
|
|
<A HREF="ControllingLineWrapping.html">Next</A>
|
|
</BODY>
|
|
</HTML>
|
|
|