|
Name |
|
Date |
Size |
#Lines |
LOC |
| .. | | - | - |
| doc/ | H | - | - | 5,555 | 4,724 |
| examples/ | H | - | - | 1,239 | 888 |
| fuzz/ | H | - | - | 758 | 565 |
| lib/ | H | - | - | 19,464 | 14,738 |
| tests/ | H | - | - | 20,878 | 15,934 |
| xmlwf/ | H | - | - | 3,919 | 2,909 |
| AUTHORS | H A D | 07-Nov-2018 | 142 | 11 | 9 |
| COPYING | H A D | 02-Apr-2025 | 1.1 KiB | 22 | 18 |
| Changes | H A D | 01-Sep-2026 | 109.5 KiB | 2,229 | 2,060 |
| FREEBSD-Xlist | H A D | 31-May-2024 | 166 | 22 | 21 |
| Makefile.am | H A D | 11-Aug-2026 | 6.2 KiB | 187 | 131 |
| Makefile.in | H A D | 11-Aug-2026 | 38.2 KiB | 1,153 | 1,005 |
| README.md | H A D | 01-Sep-2026 | 9.7 KiB | 304 | 214 |
| buildconf.sh | H A D | 28-Sep-2024 | 1.7 KiB | 36 | 2 |
| configure.ac | H A D | 01-Sep-2026 | 23.2 KiB | 604 | 532 |
| expat_config.h.in | H A D | 27-Apr-2026 | 3.8 KiB | 143 | 99 |
| fix-xmltest-log.sh | H A D | 01-Sep-2026 | 2.5 KiB | 55 | 21 |
| run.sh.in | H A D | 18-Jan-2022 | 1.8 KiB | 48 | 15 |
| test-driver-wrapper.sh | H A D | 18-Jan-2022 | 1.9 KiB | 45 | 10 |
README.md
1[](https://github.com/libexpat/libexpat/actions/workflows/linux.yml)
2[](https://repology.org/metapackage/expat/versions)
3[](https://sourceforge.net/projects/expat/files/)
4[](https://github.com/libexpat/libexpat/releases)
5[](https://www.bestpractices.dev/projects/10205)
6
7> [!CAUTION]
8>
9> Expat has **unfixed security issues**!
10> Please see https://github.com/libexpat/libexpat/issues/1160 for details.
11
12> [!NOTE]
13>
14> Starting 2026-08-01, for up to six months my work maintaining libexpat
15> will be funded by the [City of Munich](https://en.wikipedia.org/wiki/Munich)
16> as part of their [Open Source Sabbatical](https://opensource.muenchen.de/software/libexpat.html#open-source-sabbatical).
17> Thank you! :heart: :pray:
18
19
20# Expat, Release 2.8.4
21
22This is Expat, a C99 library for parsing
23[XML 1.0 Fourth Edition](https://www.w3.org/TR/2006/REC-xml-20060816/), started by
24[James Clark](https://en.wikipedia.org/wiki/James_Clark_%28programmer%29) in 1997.
25Expat is a stream-oriented XML parser. This means that you register
26handlers with the parser before starting the parse. These handlers
27are called when the parser discovers the associated structures in the
28document being parsed. A start tag is an example of the kind of
29structures for which you may register handlers.
30
31Expat supports the following C99 compilers:
32
33- GNU GCC >=4.5 (for use from C) or GNU GCC >=4.8.1 (for use from C++)
34- LLVM Clang >=3.5
35- Microsoft Visual Studio >=17.0/2022
36 (the oldest version supported by the [official GitHub Actions Windows images](https://github.com/actions/runner-images))
37
38Windows users can use the
39[`expat-win32bin-*.*.*.{exe,zip}` download](https://github.com/libexpat/libexpat/releases),
40which includes both pre-compiled libraries and executables, and source code for
41developers.
42
43Expat is [free software](https://www.gnu.org/philosophy/free-sw.en.html).
44You may copy, distribute, and modify it under the terms of the License
45contained in the file
46[`COPYING`](https://github.com/libexpat/libexpat/blob/master/expat/COPYING)
47distributed with this package.
48This license is the same as the MIT/X Consortium license.
49
50
51## Using libexpat in your CMake-Based Project
52
53There are three documented ways of using libexpat with CMake:
54
55### a) `find_package` with Module Mode
56
57This approach leverages CMake's own [module `FindEXPAT`](https://cmake.org/cmake/help/latest/module/FindEXPAT.html).
58
59Notice the *uppercase* `EXPAT` in the following example:
60
61```cmake
62cmake_minimum_required(VERSION 3.10)
63
64project(hello VERSION 1.0.0)
65
66find_package(EXPAT 2.2.8 MODULE REQUIRED)
67
68add_executable(hello
69 hello.c
70)
71
72target_link_libraries(hello PUBLIC EXPAT::EXPAT)
73```
74
75### b) `find_package` with Config Mode
76
77This approach requires files from…
78
79- libexpat >=2.2.8 where packaging uses the CMake build system
80or
81- libexpat >=2.3.0 where packaging uses the GNU Autotools build system
82 on Linux
83or
84- libexpat >=2.4.0 where packaging uses the GNU Autotools build system
85 on macOS or MinGW.
86
87Notice the *lowercase* `expat` in the following example:
88
89```cmake
90cmake_minimum_required(VERSION 3.10)
91
92project(hello VERSION 1.0.0)
93
94find_package(expat 2.2.8 CONFIG REQUIRED char dtd ns)
95
96add_executable(hello
97 hello.c
98)
99
100target_link_libraries(hello PUBLIC expat::expat)
101```
102
103### c) The `FetchContent` module
104
105This approach — as demonstrated below — requires CMake >=3.18 for both the
106[`FetchContent` module](https://cmake.org/cmake/help/latest/module/FetchContent.html)
107and its support for the `SOURCE_SUBDIR` option to be available.
108
109Please note that:
110- Use of the `FetchContent` module with *non-release* SHA1s or `master`
111 of libexpat is neither advised nor considered officially supported.
112- Pinning to a specific commit is great for robust CI.
113- Pinning to a specific commit needs updating every time there is a new
114 release of libexpat — either manually or through automation —,
115 to not miss out on libexpat security updates.
116
117For an example that pulls in libexpat via Git:
118
119```cmake
120cmake_minimum_required(VERSION 3.18)
121
122include(FetchContent)
123
124project(hello VERSION 1.0.0)
125
126FetchContent_Declare(
127 expat
128 GIT_REPOSITORY https://github.com/libexpat/libexpat/
129 GIT_TAG 000000000_GIT_COMMIT_SHA1_HERE_000000000 # i.e. Git tag R_X_Y_Z
130 SOURCE_SUBDIR expat/
131)
132
133FetchContent_MakeAvailable(expat)
134
135add_executable(hello
136 hello.c
137)
138
139target_link_libraries(hello PUBLIC expat)
140```
141
142
143## Building from a Git Clone
144
145If you are building Expat from a check-out from the
146[Git repository](https://github.com/libexpat/libexpat/),
147you need to run a script that generates the configure script using the
148GNU autoconf and libtool tools. To do this, you need to have
149autoconf 2.58 or newer. Run the script like this:
150
151```console
152./buildconf.sh
153```
154
155Once this has been done, follow the same instructions as for building
156from a source distribution.
157
158
159## Building from a Source Distribution
160
161### a) Building with the configure script (i.e. GNU Autotools)
162
163To build Expat from a source distribution, you first run the
164configuration shell script in the top level distribution directory:
165
166```console
167./configure
168```
169
170There are many options which you may provide to configure (which you
171can discover by running configure with the `--help` option). But the
172one of most interest is the one that sets the installation directory.
173By default, the configure script will set things up to install
174libexpat into `/usr/local/lib`, `expat.h` into `/usr/local/include`, and
175`xmlwf` into `/usr/local/bin`. If, for example, you'd prefer to install
176into `/home/me/mystuff/lib`, `/home/me/mystuff/include`, and
177`/home/me/mystuff/bin`, you can tell `configure` about that with:
178
179```console
180./configure --prefix=/home/me/mystuff
181```
182
183Another interesting option is to enable 64-bit integer support for
184line and column numbers and the over-all byte index:
185
186```console
187./configure CPPFLAGS=-DXML_LARGE_SIZE
188```
189
190However, such a modification would be a breaking change to the ABI
191and is therefore not recommended for general use — e.g. as part of
192a Linux distribution — but rather for builds with special requirements.
193
194After running the configure script, the `make` command will build
195things and `make install` will install things into their proper
196location. Have a look at the `Makefile` to learn about additional
197`make` options. Note that you need to have write permission into
198the directories into which things will be installed.
199
200If you are interested in building Expat to provide document
201information in UTF-16 encoding rather than the default UTF-8, follow
202these instructions (after having run `make distclean`).
203Please note that we configure with `--without-xmlwf` as xmlwf does not
204support this mode of compilation (yet):
205
2061. Mass-patch `Makefile.am` files to use `libexpatw.la` for a library name:
207 <br/>
208 `find . -name Makefile.am -exec sed
209 -e 's,libexpat\.la,libexpatw.la,'
210 -e 's,libexpat_la,libexpatw_la,'
211 -i.bak {} +`
212
2131. Run `automake` to re-write `Makefile.in` files:<br/>
214 `automake`
215
2161. For UTF-16 output as unsigned short (and version/error strings as char),
217 run:<br/>
218 `./configure CPPFLAGS=-DXML_UNICODE --without-xmlwf`<br/>
219 For UTF-16 output as `wchar_t` (incl. version/error strings), run:<br/>
220 `./configure CFLAGS="-g -O2 -fshort-wchar" CPPFLAGS=-DXML_UNICODE_WCHAR_T
221 --without-xmlwf`
222 <br/>Note: The latter requires libc compiled with `-fshort-wchar`, as well.
223
2241. Run `make` (which excludes xmlwf).
225
2261. Run `make install` (again, excludes xmlwf).
227
228Using `DESTDIR` is supported. It works as follows:
229
230```console
231make install DESTDIR=/path/to/image
232```
233
234overrides the in-makefile set `DESTDIR`, because variable-setting priority is
235
2361. commandline
2371. in-makefile
2381. environment
239
240Note: This only applies to the Expat library itself, building UTF-16 versions
241of xmlwf and the tests is currently not supported.
242
243A reference manual is available in the file `doc/reference.html` in this
244distribution.
245
246
247### b) Building with CMake
248
249The CMake build system is still *experimental* and may replace the primary
250build system based on GNU Autotools at some point when it is ready.
251
252
253#### Available Options
254
255For an idea of the available (non-advanced) options for building with CMake:
256
257```console
258# rm -f CMakeCache.txt ; cmake -D_EXPAT_HELP=ON -LH . | grep -B1 ':.*=' | sed 's,^--$,,'
259// Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel ...
260CMAKE_BUILD_TYPE:STRING=
261
262// Install path prefix, prepended onto install directories.
263CMAKE_INSTALL_PREFIX:PATH=/usr/local
264
265// Path to a program.
266DOCBOOK_TO_MAN:FILEPATH=/usr/bin/docbook2x-man
267
268// Build man page for xmlwf
269EXPAT_BUILD_DOCS:BOOL=ON
270
271// Build the examples for expat library
272EXPAT_BUILD_EXAMPLES:BOOL=ON
273
274// Build fuzzers for the expat library
275EXPAT_BUILD_FUZZERS:BOOL=OFF
276
277// Build pkg-config file
278EXPAT_BUILD_PKGCONFIG:BOOL=ON
279
280// Build the tests for expat library
281EXPAT_BUILD_TESTS:BOOL=ON
282
283// Build the xmlwf tool for expat library
284EXPAT_BUILD_TOOLS:BOOL=ON
285
286// Character type to use (char|ushort|wchar_t) [default=char]
287EXPAT_CHAR_TYPE:STRING=char
288
289// Install expat files in cmake install target
290EXPAT_ENABLE_INSTALL:BOOL=ON
291
292// Use /MT flag (static CRT) when compiling in MSVC
293EXPAT_MSVC_STATIC_CRT:BOOL=OFF
294
295// Build a shared expat library
296EXPAT_SHARED_LIBS:BOOL=ON
297
298// Define to provide symbol versioning for dependency generation
299EXPAT_SYMBOL_VERSIONING:BOOL=OFF
300
301// Treat all compiler warnings as errors
302EXPAT_WARNINGS_AS_ERRORS:BOOL=OFF
303```
304