Instrument Neutral Distributed Interface INDI  1.2.0
Functions
lilxml.h File Reference

A little DOM-style library to handle parsing and processing an XML file. More...

#include <stdio.h>

Go to the source code of this file.

Functions

LilXML * newLilXML (void)
 Create a new lilxml parser. More...
 
void delLilXML (LilXML *lp)
 Delete a lilxml parser. More...
 
void delXMLEle (XMLEle *e)
 Delete an XML element. More...
 
XMLEle * readXMLEle (LilXML *lp, int c, char errmsg[])
 Process an XML one char at a time. More...
 
XMLAtt * findXMLAtt (XMLEle *e, const char *name)
 Find an XML attribute within an XML element. More...
 
XMLEle * findXMLEle (XMLEle *e, const char *tag)
 Find an XML element within an XML element. More...
 
XMLEle * nextXMLEle (XMLEle *ep, int first)
 Iterate an XML element for a list of nesetd XML elements. More...
 
XMLAtt * nextXMLAtt (XMLEle *ep, int first)
 Iterate an XML element for a list of XML attributes. More...
 
XMLEle * parentXMLEle (XMLEle *ep)
 Return the parent of an XML element. More...
 
XMLEle * parentXMLAtt (XMLAtt *ap)
 Return the parent of an XML attribute. More...
 
char * tagXMLEle (XMLEle *ep)
 Return the tag of an XML element. More...
 
char * pcdataXMLEle (XMLEle *ep)
 Return the pcdata of an XML element. More...
 
char * nameXMLAtt (XMLAtt *ap)
 Return the name of an XML attribute. More...
 
char * valuXMLAtt (XMLAtt *ap)
 Return the value of an XML attribute. More...
 
int pcdatalenXMLEle (XMLEle *ep)
 Return the number of characters in pcdata in an XML element. More...
 
int nXMLEle (XMLEle *ep)
 Return the number of nested XML elements in a parent XML element. More...
 
int nXMLAtt (XMLEle *ep)
 Return the number of XML attributes in a parent XML element. More...
 
XMLEle * addXMLEle (XMLEle *parent, const char *tag)
 add an element with the given tag to the given element. parent can be NULL to make a new root. More...
 
void editXMLEle (XMLEle *ep, const char *pcdata)
 set the pcdata of the given element More...
 
XMLAtt * addXMLAtt (XMLEle *ep, const char *name, const char *value)
 Add an XML attribute to an existing XML element. More...
 
void rmXMLAtt (XMLEle *ep, const char *name)
 Remove an XML attribute from an XML element. More...
 
void editXMLAtt (XMLAtt *ap, const char *str)
 change the value of an attribute to str. More...
 
char * entityXML (char *str)
 return a string with all xml-sensitive characters within the passed string replaced with their entity sequence equivalents. N.B. caller must use the returned string before calling us again.
 
const char * findXMLAttValu (XMLEle *ep, const char *name)
 Find an XML element's attribute value. More...
 
XMLEle * readXMLFile (FILE *fp, LilXML *lp, char errmsg[])
 Handy wrapper to read one xml file. More...
 
void prXMLEle (FILE *fp, XMLEle *e, int level)
 Print an XML element. More...
 
int sprXMLEle (char *s, XMLEle *ep, int level)
 sample print ep to string s. N.B. s must be at least as large as that reported by sprlXMLEle()+1. N.B. set level = 0 on first call. More...
 
int sprlXMLEle (XMLEle *ep, int level)
 return number of bytes in a string guaranteed able to hold result of sprXLMEle(ep) (sans trailing \0@). N.B. set level = 0 on first call.
 

Detailed Description

A little DOM-style library to handle parsing and processing an XML file.

It only handles elements, attributes and pcdata content. <! ... > and <? ... > are silently ignored. pcdata is collected into one string, sans leading whitespace first line.
The following is an example of a cannonical usage for the lilxml library. Initialize a lil xml context and read an XML file in a root element.

#include <lilxml.h>
LilXML *lp = newLilXML();
char errmsg[1024];
XMLEle *root, *ep;
int c;
while ((c = fgetc(stdin)) != EOF) {
root = readXMLEle (lp, c, errmsg);
if (root)
break;
if (errmsg[0])
error ("Error: %s\n", errmsg);
}
// print the tag and pcdata content of each child element within the root
for (ep = nextXMLEle (root, 1); ep != NULL; ep = nextXMLEle (root, 0))
printf ("%s: %s\n", tagXMLEle(ep), pcdataXMLEle(ep));
// finished with root element and with lil xml context
delXMLEle (root);
delLilXML (lp);

Definition in file lilxml.h.