11.07.2014 Views

Flute acoustics: measurement, modelling and design - School of ...

Flute acoustics: measurement, modelling and design - School of ...

Flute acoustics: measurement, modelling and design - School of ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

APPENDIX B. PROGRAM LISTINGS 287<br />

Listing B.21: ParseXML.c<br />

/*<br />

ParseXML.c<br />

By Paul Dickens, 2006<br />

Based on ParseXML.c by Andrew Botros, 2003<br />

ParseXML.c reads a woodwind definition file for Impedance.c<br />

to use in its calculation.<br />

Refer to ParseXML.h for interface details.<br />

*/<br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include "Vector.h"<br />

#include "Woodwind.h"<br />

#include "ParseXML.h"<br />

int parseXMLFile(char* xml_filename, Woodwind* w) {<br />

xmlDocPtr doc; /* the resulting document tree */<br />

/* Read <strong>and</strong> validate XML file */<br />

if(!parseAndValidateFile(xml_filename, &doc))<br />

return 0;<br />

/* Build instrument */<br />

if(!parseWoodwind(doc, w))<br />

return 0;<br />

/* Free XML data structure */<br />

xmlFreeDoc(doc);<br />

}<br />

return 1;<br />

int parseAndValidateFile(char* xml_filename, xmlDocPtr* doc) {<br />

xmlParserCtxtPtr ctxt; /* the parser context */<br />

/* create a parser context */<br />

ctxt = xmlNewParserCtxt();<br />

if (ctxt == NULL) {<br />

fprintf(stderr, "XML Error: Failed to allocate parser context\n");<br />

return 0;<br />

}<br />

/* parse the file, activating the DTD validation option */<br />

*doc = xmlCtxtReadFile(ctxt, xml_filename, NULL,<br />

XML_PARSE_DTDVALID);<br />

/* check if parsing succeeded */<br />

if (*doc == NULL) {<br />

fprintf(stderr, "XML Error: Failed to parse %s\n", xml_filename);<br />

return 0;<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!