Instrument Neutral Distributed Interface INDI  1.9.2
lilxml.h
Go to the documentation of this file.
1 #if 0
2 liblilxml
3 Copyright (C) 2003 Elwood C. Downey
4 
5 This library is free software;
6 you can redistribute it and / or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation;
9 either
10 version 2.1 of the License, or (at your option) any later version.
11 
12 This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY;
14 without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library;
20 if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 - 1301 USA
22 
23 #endif
24 
64 #pragma once
65 
66 #include <stdio.h>
67 
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71 
72 /* opaque handle types */
73 typedef struct xml_att_ XMLAtt;
74 typedef struct xml_ele_ XMLEle;
75 typedef struct LilXML_ LilXML;
76 
81 
82 /* creation and destruction functions */
83 
87 extern LilXML *newLilXML();
88 
92 extern void delLilXML(LilXML *lp);
93 
98 extern void delXMLEle(XMLEle *e);
99 
107 extern XMLEle **parseXMLChunk(LilXML *lp, char *buf, int size, char errmsg[]);
108 
115 extern XMLEle *readXMLEle(LilXML *lp, int c, char errmsg[]);
116 
117 /* search functions */
123 extern XMLAtt *findXMLAtt(XMLEle *e, const char *name);
124 
130 extern XMLEle *findXMLEle(XMLEle *e, const char *tag);
131 
132 /* iteration functions */
138 extern XMLEle *nextXMLEle(XMLEle *ep, int first);
139 
145 extern XMLAtt *nextXMLAtt(XMLEle *ep, int first);
146 
147 /* tree functions */
151 extern XMLEle *parentXMLEle(XMLEle *ep);
152 
156 extern XMLEle *parentXMLAtt(XMLAtt *ap);
157 
158 /* access functions */
163 extern char *tagXMLEle(XMLEle *ep);
164 
169 extern char *pcdataXMLEle(XMLEle *ep);
170 
175 extern char *nameXMLAtt(XMLAtt *ap);
176 
181 extern char *valuXMLAtt(XMLAtt *ap);
182 
187 extern int pcdatalenXMLEle(XMLEle *ep);
188 
193 extern int nXMLEle(XMLEle *ep);
194 
199 extern int nXMLAtt(XMLEle *ep);
200 
201 /* editing functions */
205 extern XMLEle *addXMLEle(XMLEle *parent, const char *tag);
206 
211 extern void editXMLEle(XMLEle *ep, const char *pcdata);
212 
218 extern XMLAtt *addXMLAtt(XMLEle *ep, const char *name, const char *value);
219 
224 extern void rmXMLAtt(XMLEle *ep, const char *name);
225 
230 extern void editXMLAtt(XMLAtt *ap, const char *str);
231 
235 extern char *entityXML(char *str);
236 
237 /* convenience functions */
243 extern const char *findXMLAttValu(XMLEle *ep, const char *name);
244 
251 extern XMLEle *readXMLFile(FILE *fp, LilXML *lp, char errmsg[]);
252 
258 extern void prXMLEle(FILE *fp, XMLEle *e, int level);
259 
265 extern int sprXMLEle(char *s, XMLEle *ep, int level);
266 
270 extern int sprlXMLEle(XMLEle *ep, int level);
271 
272 /* install alternatives to malloc/realloc/free */
273 extern void indi_xmlMalloc(void *(*newmalloc)(size_t size), void *(*newrealloc)(void *ptr, size_t size),
274  void (*newfree)(void *ptr));
275 
278 #ifdef __cplusplus
279 }
280 #endif
281 
282 /* examples.
283 
284  initialize a lil xml context and read an XML file in a root element
285 
286  LilXML *lp = newLilXML();
287  char errmsg[1024];
288  XMLEle *root, *ep;
289  int c;
290 
291  while ((c = fgetc(stdin)) != EOF) {
292  root = readXMLEle (lp, c, errmsg);
293  if (root)
294  break;
295  if (errmsg[0])
296  error ("Error: %s\n", errmsg);
297  }
298 
299  print the tag and pcdata content of each child element within the root
300 
301  for (ep = nextXMLEle (root, 1); ep != NULL; ep = nextXMLEle (root, 0))
302  printf ("%s: %s\n", tagXMLEle(ep), pcdataXMLEle(ep));
303 
304 
305  finished with root element and with lil xml context
306 
307  delXMLEle (root);
308  delLilXML (lp);
309  */
310 
311 /* For RCS Only -- Do Not Edit
312  * @(#) $RCSfile$ $Date: 2007-09-17 16:34:48 +0300 (Mon, 17 Sep 2007) $ $Revision: 713418 $ $Name: $
313  */
prXMLEle
void prXMLEle(FILE *fp, XMLEle *e, int level)
Print an XML element.
Definition: lilxml.c:699
delLilXML
void delLilXML(LilXML *lp)
Delete a lilxml parser.
Definition: lilxml.c:157
Aux::ANY
@ ANY
Definition: celestronauxpacket.h:86
findXMLAtt
XMLAtt * findXMLAtt(XMLEle *e, const char *name)
Find an XML attribute within an XML element.
Definition: lilxml.c:493
addXMLEle
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.
Definition: lilxml.c:639
pcdatalenXMLEle
int pcdatalenXMLEle(XMLEle *ep)
Return the number of characters in pcdata in an XML element.
Definition: lilxml.c:581
nXMLAtt
int nXMLAtt(XMLEle *ep)
Return the number of XML attributes in a parent XML element.
Definition: lilxml.c:605
nextXMLEle
XMLEle * nextXMLEle(XMLEle *ep, int first)
Iterate an XML element for a list of nesetd XML elements.
Definition: lilxml.c:524
sprXMLEle
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....
Definition: lilxml.c:735
entityXML
char * entityXML(char *str)
return a string with all xml-sensitive characters within the passed string replaced with their entity...
Definition: lilxml.c:815
readXMLEle
XMLEle * readXMLEle(LilXML *lp, int c, char errmsg[])
Process an XML one char at a time.
Definition: lilxml.c:383
readXMLFile
XMLEle * readXMLFile(FILE *fp, LilXML *lp, char errmsg[])
Handy wrapper to read one xml file.
Definition: lilxml.c:622
tagXMLEle
char * tagXMLEle(XMLEle *ep)
Return the tag of an XML element.
Definition: lilxml.c:569
sprlXMLEle
int sprlXMLEle(XMLEle *ep, int level)
return number of bytes in a string guaranteed able to hold result of sprXLMEle(ep) (sans trailing \0@...
Definition: lilxml.c:776
nextXMLAtt
XMLAtt * nextXMLAtt(XMLEle *ep, int first)
Iterate an XML element for a list of XML attributes.
Definition: lilxml.c:541
findXMLAttValu
const char * findXMLAttValu(XMLEle *ep, const char *name)
Find an XML element's attribute value.
Definition: lilxml.c:613
parentXMLEle
XMLEle * parentXMLEle(XMLEle *ep)
Return the parent of an XML element.
Definition: lilxml.c:555
indi_xmlMalloc
void indi_xmlMalloc(void *(*newmalloc)(size_t size), void *(*newrealloc)(void *ptr, size_t size), void(*newfree)(void *ptr))
editXMLAtt
void editXMLAtt(XMLAtt *ap, const char *str)
change the value of an attribute to str.
Definition: lilxml.c:689
xml_att_
Definition: lilxml.c:120
xml_ele_
Definition: lilxml.c:105
parseXMLChunk
XMLEle ** parseXMLChunk(LilXML *lp, char *buf, int size, char errmsg[])
Process an XML chunk.
Definition: lilxml.c:213
newLilXML
LilXML * newLilXML()
Create a new lilxml parser.
Definition: lilxml.c:148
nameXMLAtt
char * nameXMLAtt(XMLAtt *ap)
Return the name of an XML attribute.
Definition: lilxml.c:587
findXMLEle
XMLEle * findXMLEle(XMLEle *e, const char *tag)
Find an XML element within an XML element.
Definition: lilxml.c:506
parentXMLAtt
XMLEle * parentXMLAtt(XMLAtt *ap)
Return the parent of an XML attribute.
Definition: lilxml.c:561
rmXMLAtt
void rmXMLAtt(XMLEle *ep, const char *name)
Remove an XML attribute from an XML element.
Definition: lilxml.c:673
LilXML_
Definition: lilxml.c:91
addXMLAtt
XMLAtt * addXMLAtt(XMLEle *ep, const char *name, const char *value)
Add an XML attribute to an existing XML element.
Definition: lilxml.c:664
pcdataXMLEle
char * pcdataXMLEle(XMLEle *ep)
Return the pcdata of an XML element.
Definition: lilxml.c:575
delXMLEle
void delXMLEle(XMLEle *e)
delXMLEle Delete XML element.
Definition: lilxml.c:165
editXMLEle
void editXMLEle(XMLEle *ep, const char *pcdata)
set the pcdata of the given element
Definition: lilxml.c:656
valuXMLAtt
char * valuXMLAtt(XMLAtt *ap)
Return the value of an XML attribute.
Definition: lilxml.c:593
nXMLEle
int nXMLEle(XMLEle *ep)
Return the number of nested XML elements in a parent XML element.
Definition: lilxml.c:599