\section{cmml-write.c}
{\bf Writing a CMML file}

Although libcmml was created mainly for the purpose of parsing existing CMML files, it also provides rudimentary support for creating CMML files. This basically consists in providing the data structures for the different tags and API functions to print those tags. There is no validation or sequence checking available for the writing side.

The general sequence of API calls is the following:

\begin{itemize}
\item create a \doxyref{CMML\_\-Preamble}{p.}{structCMML__Preamble} with \doxyref{cmml\_\-preamble\_\-new()}{p.}{cmml_8h_1f187f66862f4b7d50df7717907ce554} and print it with \doxyref{cmml\_\-preamble\_\-snprint()}{p.}{cmml_8h_61c5aa16f364e3b705ad42a63fe77d81}\item create a \doxyref{CMML\_\-Head}{p.}{structCMML__Head} with \doxyref{cmml\_\-head\_\-new()}{p.}{cmml_8h_bd68056f90e67a10f7275e830c1b7d6f}, change the attribute and element contents in the \doxyref{CMML\_\-Head}{p.}{structCMML__Head} structure, and print it with \doxyref{cmml\_\-head\_\-snprint()}{p.}{cmml_8h_122f056d7e6ba46bf95c01b72a49a9e2} or \doxyref{cmml\_\-head\_\-pretty\_\-snprint()}{p.}{cmml_8h_0d2218b4dcd2f8b6486a73f24207ff87}\item create one or more \doxyref{CMML\_\-Clip}{p.}{structCMML__Clip} with \doxyref{cmml\_\-clip\_\-new()}{p.}{cmml_8h_d7da38d4f76aff326bc33dc4046b091a}, change the attribute and element contents in the \doxyref{CMML\_\-Clip}{p.}{structCMML__Clip} structures, and print them with \doxyref{cmml\_\-clip\_\-snprint()}{p.}{cmml_8h_49c51358d878214dd9843be538d3e2f4} or \doxyref{cmml\_\-clip\_\-pretty\_\-snprint()}{p.}{cmml_8h_d5caeeabea9df462139f74483f135870}\item print the final \char`\"{}$<$/cmml$>$\char`\"{} tag\end{itemize}


This procedure is illustrated in cmml-write.c:



\begin{DocInclude}\begin{verbatim}/* Copyright (C) 2003- CSIRO Australia

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
   are met:
   
   - Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
   
   - Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.
   
   - Neither the name of the CSIRO nor the names of its
   contributors may be used to endorse or promote products derived from
   this software without specific prior written permission.
   
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
   PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <stdio.h>
#include <string.h>

#include <cmml.h>

#define BUFSIZE 100000

int main(int argc, char *argv[])
{
  CMML_Preamble * pre = NULL;
  CMML_Head * head = NULL;
  CMML_Clip * clip = NULL;
  CMML_Time * start = NULL, * end = NULL;
  char buf[BUFSIZE];

  /* write preamble */
  pre = cmml_preamble_new("UTF-8", NULL, NULL, NULL, NULL);
  cmml_preamble_snprint (buf, BUFSIZE, pre);
  puts(buf);
  cmml_preamble_destroy(pre);

  /* write head */
  head = cmml_head_new();
  head->title = strdup("This is a test file");
  cmml_head_snprint (buf, BUFSIZE, head);
  puts(buf);
  cmml_head_destroy(head);

  /* write a clip for the interval 0.6 to 3.5 seconds */
  cmml_npt_snprint (buf, BUFSIZE, 0.6);
  start = cmml_time_new (buf);

  cmml_npt_snprint (buf, BUFSIZE, 3.5);
  end = cmml_time_new (buf);

  clip = cmml_clip_new(start, end);
  clip->anchor_href = strdup("http://www.annodex.net/");
  clip->anchor_text = strdup("hyperlink to annodex.net");
  clip->desc_text = strdup("This is a clip");
  cmml_clip_snprint (buf, BUFSIZE, clip);
  puts (buf);
  cmml_clip_destroy(clip);

  printf ("</cmml>\n");

  exit(0);
}
\end{verbatim}
\end{DocInclude}
 