Commit 7a51d3c4 authored by Michael R Sweet's avatar Michael R Sweet

Initial revision

parents
This diff is collapsed.
#
# "$Id: Makefile.in,v 1.1 2003/06/03 19:46:30 mike Exp $"
#
# Makefile for mini-XML, a small XML-like file parsing library.
#
# Copyright 2003 by Michael Sweet.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2, or (at your option) any later version.
#
# This program 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 General Public License for more details.
#
#
# Compiler tools definitions...
#
AR = @AR@
ARFLAGS = @ARFLAGS@
CC = @CC@
CFLAGS = @CFLAGS@ @CPPFLAGS@
LDFLAGS = @LDFLAGS@
RANLIB = @RANLIB@
SHELL = /bin/sh
#
# Configured directories...
#
prefix = @prefix@
exec_prefix = @exec_prefix@
includedir = @includedir@
libdir = @libdir@
#
# Rules...
#
.SUFFIXES: .c .o
.c.o:
$(CC) $(CFLAGS) -c $<
#
# Targets...
#
LIBOBJS = mxml-attr.o mxml-file.o mxml-node.o mxml-search.o
OBJS = testmxml.o $(LIBOBJS)
TARGETS = libmxml.a testmxml
#
# Make everything...
#
all: $(TARGETS)
#
# Clean everything...
#
clean:
rm -f $(OBJS) $(TARGETS)
rm -f *.bck *.bak
rm -f config.cache config.log config.status
rm -rf autom4te*.cache
#
# Install everything...
#
install: $(TARGETS)
-mkdir -p $(libdir)
cp libmxml.a $(libdir)
-mkdir -p $(includedir)
cp mxml.h $(includedir)
#
# libmxml.a
#
libmxml.a: $(LIBOBJS)
rm -f $@
$(AR) $(ARFLAGS) $@ $(LIBOBJS)
$(RANLIB) $@
$(LIBOBJS): mxml.h
#
# testmxml
#
testmxml: libmxml.a testmxml.o
$(CC) $(LDFLAGS) -o $@ testmxml.o libmxml.a
testmxml.o: mxml.h
#
# End of "$Id: Makefile.in,v 1.1 2003/06/03 19:46:30 mike Exp $".
#
README - 06/03/2003
-------------------
INTRODUCTION
This README file describes the Mini-XML library version 0.9.
Mini-XML is a small XML parsing library that you can use to
read XML and XML-like data files in your application without
requiring large non-standard libraries. Mini-XML only
requires an ANSI C compatible compiler (GCC works, as do
most vendors' ANSI C compilers) and a "make" program.
Mini-XML was created to support the basic hierarchy provided
by XML and some simple data types, but doesn't do validation
or other types of processing on the data.
BUILDING Mini-XML
Mini-XML comes with an autoconf-based configure script; just
type the following command to get things going:
./configure
The default install prefix is /usr/local, which can be
overridden using the --prefix option:
./configure --prefix=/foo
Once you have configured the software, type "make" to do the
build and then run the test program to verify that things
are working, as follows:
make
./testmxml test.xml
INSTALLING Mini-XML
The "install" target will install Mini-XML in the lib and
include directories:
make install
Once you have installed it, use the "-lmxml" option to link
your application against it.
DOCUMENTATION
The documentation is currently just in this README file. At
some point I'll probably do some proper documentation, but
for now just read here and look at the testmxml.c source
file for an example of reading and printing the contents of
an XML file to stdout.
Mini-XML provides a single header file which you include:
#include <mxml.h>
Nodes are defined by the "mxml_node_t" structure; the "type"
member defines the node type (element, integer, opaque,
real, or text) which determines which value you want to look
at in the "value" union. New nodes can be created using the
"mxmlNewElement()", "mxmlNewInteger()", "mxmlNewOpaque()",
"mxmlNewReal()", and "mxmlNewText()" functions. Only
elements can have child nodes, and the top node must be an
element, usually "?xml".
You load an XML file using the "mxmlLoadFile()" function:
FILE *fp;
mxml_node_t *tree;
fp = fopen("filename.xml", "r");
tree = mxmlLoadFile(NULL, fp, MXML_NO_CALLBACK);
fclose(fp);
Similarly, you save an XML file using the "mxmlSaveFile()"
function:
FILE *fp;
mxml_node_t *tree;
fp = fopen("filename.xml", "w");
mxmlSaveFile(tree, fp);
fclose(fp);
You can find a named element/node using the
"mxmlFindElement()" function:
mxml_node_t *node = mxmlFindElement(tree, tree, "name");
You can also iterate with the same function:
mxml_node_t *node;
for (node = mxmlFindElement(tree, tree, "name");
node != NULL;
node = mxmlFindElement(node, tree, "name"))
{
... do something ...
}
Finally, once you are done with the XML data, use the
"mxmlDelete()" function to free the memory that is used:
mxmlDelete(tree);
GETTING HELP AND REPORTING PROBLEMS
You can email me at "mxml@easysw.com" to report problems
and/or ask for help. Just don't expect an instant response,
as I get a *lot* of email...
LEGAL STUFF
The Mini-XML library is Copyright 2003 by Michael Sweet.
This library is free software; you can redistribute it
and/or modify it under the terms of the GNU Library General
Public License as published by the Free Software Foundation;
either version 2 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 Library General Public License for
more details.
You should have received a copy of the GNU Library General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
02139, USA.
This diff is collapsed.
dnl
dnl "$Id: configure.in,v 1.1 2003/06/03 19:46:30 mike Exp $"
dnl
dnl Configuration script for mini-XML, a small XML-like file parsing library.
dnl
dnl Copyright 2003 by Michael Sweet.
dnl
dnl This program is free software; you can redistribute it and/or
dnl modify it under the terms of the GNU Library General Public
dnl License as published by the Free Software Foundation; either
dnl version 2, or (at your option) any later version.
dnl
dnl This program is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dnl GNU General Public License for more details.
dnl
AC_INIT(mxml.h)
#AC_PREFIX_DEFAULT(/usr)
dnl Checks for programs...
AC_PATH_PROG(AR,ar)
AC_PROG_CC
AC_PROG_CXX
AC_PROG_RANLIB
dnl Flags for "ar" command...
case "`uname`" in
Darwin* | *BSD*)
ARFLAGS="-rcv"
;;
*)
ARFLAGS="crvs"
;;
esac
AC_SUBST(ARFLAGS)
dnl Output the makefile...
AC_OUTPUT(Makefile)
dnl
dnl End of "$Id: configure.in,v 1.1 2003/06/03 19:46:30 mike Exp $".
dnl
<HTML>
<HEAD>
<TITLE>Mini-XML Home Page</TITLE>
</HEAD>
<BODY>
<SPAN STYLE="text-align: justify;">
<H1 ALIGN="CENTER">Mini-XML Home Page</H1>
<P ALIGN="CENTER">Current Release: v0.9 ( <A
HREF="mxml-0.9.tar.gz">download 40k</A> )</P>
<H2>Introduction</H2>
<P>Mini-XML is a small XML parsing library that you can use to
read XML and XML-like data files in your application without
requiring large non-standard libraries. Mini-XML only requires
an ANSI C compatible compiler (GCC works, as do most vendors'
ANSI C compilers) and a "make" program.
<P>Mini-XML was created to support the basic hierarchy provided
by XML and some simple data types, but doesn't do validation or
other types of processing on the data.
<H2>Building Mini-XML</H2>
<P>Mini-XML comes with an autoconf-based configure script; just
type the following command to get things going:
<PRE>
./configure
</PRE>
<P>The default install prefix is /usr/local, which can be
overridden using the --prefix option:
<PRE>
./configure --prefix=/foo
</PRE>
<P>Once you have configured the software, type "make" to do the
build and then run the test program to verify that things are
working, as follows:
<PRE>
make
./testmxml test.xml
</PRE>
<H2>Installing Mini-XML</H2>
<P>The "install" target will install Mini-XML in the lib and
include directories:
<PRE>
make install
</PRE>
<P>Once you have installed it, use the "-lmxml" option to link
your application against it.
<H2>Documentation</H2>
<P>The documentation is currently just in this page. At
some point I'll probably do some proper documentation, but
for now just read here and look at the testmxml.c source
file for an example of reading and printing the contents of
an XML file to stdout.
<P>Mini-XML provides a single header file which you include:
<PRE>
#include &lt;mxml.h>
</PRE>
<P>Nodes are defined by the "mxml_node_t" structure; the "type"
member defines the node type (element, integer, opaque,
real, or text) which determines which value you want to look
at in the "value" union. New nodes can be created using the
"mxmlNewElement()", "mxmlNewInteger()", "mxmlNewOpaque()",
"mxmlNewReal()", and "mxmlNewText()" functions. Only
elements can have child nodes, and the top node must be an
element, usually "?xml".
<P>You load an XML file using the "mxmlLoadFile()" function:
<PRE>
FILE *fp;
mxml_node_t *tree;
fp = fopen("filename.xml", "r");
tree = mxmlLoadFile(NULL, fp, MXML_NO_CALLBACK);
fclose(fp);
</PRE>
<P>Similarly, you save an XML file using the "mxmlSaveFile()"
function:
<PRE>
FILE *fp;
mxml_node_t *tree;
fp = fopen("filename.xml", "w");
mxmlSaveFile(tree, fp);
fclose(fp);
</PRE>
<P>You can find a named element/node using the
"mxmlFindElement()" function:
<PRE>
mxml_node_t *node = mxmlFindElement(tree, tree, "name");
</PRE>
<P>You can also iterate with the same function:
<PRE>
mxml_node_t *node;
for (node = mxmlFindElement(tree, tree, "name");
node != NULL;
node = mxmlFindElement(node, tree, "name"))
{
... do something ...
}
</PRE>
<P>Finally, once you are done with the XML data, use the
"mxmlDelete()" function to free the memory that is used:
<PRE>
mxmlDelete(tree);
</PRE>
<H2>Getting Help and Reporting Problems</H2>
<P>You can email me at "mxml <I>at</I> easysw <I>dot</I> com" to
report problems and/or ask for help. Just don't expect an
instant response, as I get a *lot* of email...
<H2>Legal Stuff</H2>
<P>The Mini-XML library is Copyright 2003 by Michael Sweet.
<P>This library is free software; you can redistribute it
and/or modify it under the terms of the GNU Library General
Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any
later version.
<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>You should have received a copy of the GNU Library General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
02139, USA.
</SPAN>
</BODY>
</HTML>
/*
* "$Id: mxml-attr.c,v 1.1 2003/06/03 19:46:30 mike Exp $"
*
* Attribute support code for mini-XML, a small XML-like file parsing library.
*
* Copyright 2003 by Michael Sweet.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* Contents:
*
* mxmlElementGetAttr() - Get an attribute.
* mxmlElementSetAttr() - Set an attribute.
*/
/*
* Include necessary headers...
*/
#include "mxml.h"
/*
* 'mxmlElementGetAttr()' - Get an attribute.
*/
const char * /* O - Attribute value or NULL */
mxmlElementGetAttr(mxml_node_t *node, /* I - Element node */
const char *name) /* I - Name of attribute */
{
int i; /* Looping var */
mxml_attr_t *attr; /* Cirrent attribute */
/*
* Range check input...
*/
if (!node || node->type != MXML_ELEMENT || !name)
return (NULL);
/*
* Look for the attribute...
*/
for (i = node->value.element.num_attrs, attr = node->value.element.attrs;
i > 0;
i --, attr ++)
if (!strcmp(attr->name, name))
return (attr->value);
/*
* Didn't find attribute, so return NULL...
*/
return (NULL);
}
/*
* 'mxmlElementSetAttr()' - Set an attribute.
*/
void
mxmlElementSetAttr(mxml_node_t *node, /* I - Element node */
const char *name, /* I - Name of attribute */
const char *value) /* I - Attribute value */
{
int i; /* Looping var */
mxml_attr_t *attr; /* New attribute */
/*
* Range check input...
*/
if (!node || node->type != MXML_ELEMENT || !name || !value)
return;
/*
* Look for the attribute...
*/
for (i = node->value.element.num_attrs, attr = node->value.element.attrs;
i > 0;
i --, attr ++)
if (!strcmp(attr->name, name))
{
/*
* Replace the attribute value and return...
*/
free(attr->value);
attr->value = strdup(value);
return;
}
/*
* Attribute not found, so add a new one...
*/
if (node->value.element.num_attrs == 0)
attr = malloc(sizeof(mxml_attr_t));
else
attr = realloc(node->value.element.attrs,
(node->value.element.num_attrs + 1) * sizeof(mxml_attr_t));
if (!attr)
{
fprintf(stderr, "Unable to allocate memory for attribute '%s' in element %s!\n",
name, node->value.element.name);
return;
}
node->value.element.attrs = attr;
attr += node->value.element.num_attrs;
attr->name = strdup(name);
attr->value = strdup(value);
if (!attr->name || !attr->value)
{
if (attr->name)
free(attr->name);
if (attr->value)
free(attr->value);
fprintf(stderr, "Unable to allocate memory for attribute '%s' in element %s!\n",
name, node->value.element.name);
return;
}
node->value.element.num_attrs ++;
}
/*
* End of "$Id: mxml-attr.c,v 1.1 2003/06/03 19:46:30 mike Exp $".
*/
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<option>
<keyword type="opaque">InputSlot</keyword>
<default type="opaque">Auto</default>
<text>Media Source</text>
<order type="real">10.0</order>
<choice>
<keyword type="opaque">Auto</keyword>
<text>Auto Tray Selection</text>
<code type="opaque"/>
</choice>
<choice>
<keyword type="opaque">Upper</keyword>
<text>Tray 1</text>
<code type="opaque">&lt;&lt;/MediaPosition 0>>setpagedevice</code>
</choice>
<choice>
<keyword type="opaque">Lower</keyword>
<text>Tray 2</text>
<code type="opaque">&lt;&lt;/MediaPosition 1>>setpagedevice</code>
</choice>
</option>
<integer>123</integer>
<string>Now is the time for all good men to come to the aid of
their country.</string>
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment