1 //==========================================================================
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 2005 eCosCentric Ltd
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //==========================================================================
41 //#####DESCRIPTIONBEGIN####
43 // Author(s): Aaron Voisine
44 // Contributors: Matt Jerdonek
49 // This code is part of eCos (tm).
51 //####DESCRIPTIONEND####
53 //==========================================================================
57 * Copyright 2004 Aaron Voisine <aaron@voisine.org>
59 * Permission is hereby granted, free of charge, to any person obtaining
60 * a copy of this software and associated documentation files (the
61 * "Software"), to deal in the Software without restriction, including
62 * without limitation the rights to use, copy, modify, merge, publish,
63 * distribute, sublicense, and/or sell copies of the Software, and to
64 * permit persons to whom the Software is furnished to do so, subject to
65 * the following conditions:
67 * The above copyright notice and this permission notice shall be included
68 * in all copies or substantial portions of the Software.
70 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
71 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
72 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
73 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
74 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
75 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
76 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
91 #define EZXML_BUFSIZE 1024
93 // returns the next tag of the same name in the same section and depth or NULL
95 #define ezxml_next(xml) xml->next
97 // returns the tag character content or empty string if none
98 #define ezxml_txt(xml) xml->txt
100 typedef struct ezxml *ezxml_t;
102 char *name; // tag name
103 char **attr; // tag attributes { name, value, name, value, ... NULL }
104 char *txt; // tag character content, empty string if none
105 size_t off; // tag offset in parent tag character content
106 ezxml_t next; // next tag with same name in this section at this depth
107 ezxml_t sibling; // next tag with different name in same section and depth
108 ezxml_t ordered; // next tag, same section and depth, in original order
109 ezxml_t child; // head of sub tag list, NULL if none
110 ezxml_t parent; // parent tag, NULL if current tag is root tag
111 short flags; // additional information, only used internally for now
114 // Given a string of xml data and its length, parses it and creates an ezxml
115 // structure. For efficiency, modifies the data by adding null terminators
116 // and decoding ampersand sequences. If you don't want this, copy the data and
117 // pass in the copy. Returns NULL on failure.
118 ezxml_t ezxml_parse_str(char *s, size_t len);
120 // A wrapper for ezxml_parse_str() that accepts a file descriptor. First
121 // attempts to mem map the file. Failing that, reads the file into memory.
122 // Returns NULL on failure.
123 ezxml_t ezxml_parse_fd(int fd);
125 // a wrapper for ezxml_parse_fd() that accepts a file name
126 ezxml_t ezxml_parse_file(const char *file);
128 // Wrapper for ezxml_parse_str() that accepts a file stream. Reads the entire
129 // stream into memory and then parses it. For xml files, use ezxml_parse_file()
130 // or ezxml_parse_fd()
131 ezxml_t ezxml_parse_fp(FILE *fp);
133 // returns the first child tag (one level deeper) with the given name or NULL if
135 ezxml_t ezxml_child(ezxml_t xml, const char *name);
137 // Returns the Nth tag with the same name in the same section at the same depth
138 // or NULL if not found. An index of 0 returns the tag given.
139 ezxml_t ezxml_idx(ezxml_t xml, int idx);
141 // returns the value of the requested tag attribute, or NULL if not found
142 const char *ezxml_attr(ezxml_t xml, const char *attr);
144 // Traverses the ezxml sturcture to retrive a specific subtag. Takes a variable
145 // length list of tag names and indexes. Final index must be -1. Example:
146 // title = ezxml_get(library, "shelf", 0, "book", 2, "title", -1);
147 // This retrieves the title of the 3rd book on the 1st shelf of library.
148 // Returns NULL if not found.
149 ezxml_t ezxml_get(ezxml_t xml, ...);
151 // Converts an ezxml structure back to xml. Returns a string of xml data that
153 char *ezxml_toxml(ezxml_t xml);
155 // returns a NULL terminated array of processing instructions for the given
157 const char **ezxml_pi(ezxml_t xml, const char *target);
159 // frees the memory allocated for an ezxml structure
160 void ezxml_free(ezxml_t xml);
162 // returns parser error message or empty string if none
163 const char *ezxml_error(ezxml_t xml);