- Notifications
You must be signed in to change notification settings - Fork493
🌿 Fast streaming XML parser written in C99 with >90% test coverage; moved from SourceForge to GitHub
License
libexpat/libexpat
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Caution
Expat isunderstaffed and without funding.There is acall for help with detailsat the top of theChanges file.
This is Expat, a C99 library for parsingXML 1.0 Fourth Edition, started byJames Clark in 1997.Expat is a stream-oriented XML parser. This means that you registerhandlers with the parser before starting the parse. These handlersare called when the parser discovers the associated structures in thedocument being parsed. A start tag is an example of the kind ofstructures for which you may register handlers.
Expat supports the following C99 compilers:
- GNU GCC >=4.5 (for use from C) or GNU GCC >=4.8.1 (for use from C++)
- LLVM Clang >=3.5
- Microsoft Visual Studio >=17.0/2022(the oldest version supported by theofficial GitHub Actions Windows images)
Windows users can use theexpat-win32bin-*.*.*.{exe,zip} download,which includes both pre-compiled libraries and executables, and source code fordevelopers.
Expat isfree software.You may copy, distribute, and modify it under the terms of the Licensecontained in the fileCOPYINGdistributed with this package.This license is the same as the MIT/X Consortium license.
There are three documented ways of using libexpat with CMake:
This approach leverages CMake's ownmoduleFindEXPAT.
Notice theuppercaseEXPAT in the following example:
cmake_minimum_required(VERSION 3.10)project(helloVERSION 1.0.0)find_package(EXPAT 2.2.8 MODULE REQUIRED)add_executable(hello hello.c)target_link_libraries(helloPUBLIC EXPAT::EXPAT)
This approach requires files from…
- libexpat >=2.2.8 where packaging uses the CMake build systemor
- libexpat >=2.3.0 where packaging uses the GNU Autotools build systemon Linuxor
- libexpat >=2.4.0 where packaging uses the GNU Autotools build systemon macOS or MinGW.
Notice thelowercaseexpat in the following example:
cmake_minimum_required(VERSION 3.10)project(helloVERSION 1.0.0)find_package(expat 2.2.8 CONFIG REQUIRED char dtd ns)add_executable(hello hello.c)target_link_libraries(helloPUBLIC expat::expat)
This approach — as demonstrated below — requires CMake >=3.18 for both theFetchContent moduleand its support for theSOURCE_SUBDIR option to be available.
Please note that:
- Use of the
FetchContentmodule withnon-release SHA1s ormasterof libexpat is neither advised nor considered officially supported. - Pinning to a specific commit is great for robust CI.
- Pinning to a specific commit needs updating every time there is a newrelease of libexpat — either manually or through automation —,to not miss out on libexpat security updates.
For an example that pulls in libexpat via Git:
cmake_minimum_required(VERSION 3.18)include(FetchContent)project(helloVERSION 1.0.0)FetchContent_Declare( expat GIT_REPOSITORY https://github.com/libexpat/libexpat/ GIT_TAG 000000000_GIT_COMMIT_SHA1_HERE_000000000# i.e. Git tag R_X_Y_Z SOURCE_SUBDIR expat/)FetchContent_MakeAvailable(expat)add_executable(hello hello.c)target_link_libraries(helloPUBLIC expat)
If you are building Expat from a check-out from theGit repository,you need to run a script that generates the configure script using theGNU autoconf and libtool tools. To do this, you need to haveautoconf 2.58 or newer. Run the script like this:
./buildconf.shOnce this has been done, follow the same instructions as for buildingfrom a source distribution.
To build Expat from a source distribution, you first run theconfiguration shell script in the top level distribution directory:
./configureThere are many options which you may provide to configure (which youcan discover by running configure with the--help option). But theone of most interest is the one that sets the installation directory.By default, the configure script will set things up to installlibexpat into/usr/local/lib,expat.h into/usr/local/include, andxmlwf into/usr/local/bin. If, for example, you'd prefer to installinto/home/me/mystuff/lib,/home/me/mystuff/include, and/home/me/mystuff/bin, you can tellconfigure about that with:
./configure --prefix=/home/me/mystuffAnother interesting option is to enable 64-bit integer support forline and column numbers and the over-all byte index:
./configure CPPFLAGS=-DXML_LARGE_SIZEHowever, such a modification would be a breaking change to the ABIand is therefore not recommended for general use — e.g. as part ofa Linux distribution — but rather for builds with special requirements.
After running the configure script, themake command will buildthings andmake install will install things into their properlocation. Have a look at theMakefile to learn about additionalmake options. Note that you need to have write permission intothe directories into which things will be installed.
If you are interested in building Expat to provide documentinformation in UTF-16 encoding rather than the default UTF-8, followthese instructions (after having runmake distclean).Please note that we configure with--without-xmlwf as xmlwf does notsupport this mode of compilation (yet):
Mass-patch
Makefile.amfiles to uselibexpatw.lafor a library name:find . -name Makefile.am -exec sed -e 's,libexpat\.la,libexpatw.la,' -e 's,libexpat_la,libexpatw_la,' -i.bak {} +Run
automaketo re-writeMakefile.infiles:automakeFor UTF-16 output as unsigned short (and version/error strings as char),run:
./configure CPPFLAGS=-DXML_UNICODE --without-xmlwf
For UTF-16 output aswchar_t(incl. version/error strings), run:./configure CFLAGS="-g -O2 -fshort-wchar" CPPFLAGS=-DXML_UNICODE_WCHAR_T --without-xmlwf
Note: The latter requires libc compiled with-fshort-wchar, as well.Run
make(which excludes xmlwf).Run
make install(again, excludes xmlwf).
UsingDESTDIR is supported. It works as follows:
make install DESTDIR=/path/to/imageoverrides the in-makefile setDESTDIR, because variable-setting priority is
- commandline
- in-makefile
- environment
Note: This only applies to the Expat library itself, building UTF-16 versionsof xmlwf and the tests is currently not supported.
A reference manual is available in the filedoc/reference.html in thisdistribution.
The CMake build system is stillexperimental and may replace the primarybuild system based on GNU Autotools at some point when it is ready.
For an idea of the available (non-advanced) options for building with CMake:
#rm -f CMakeCache.txt; cmake -D_EXPAT_HELP=ON -LH.| grep -B1':.*='| sed's,^--$,,'// Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel ...CMAKE_BUILD_TYPE:STRING=// Install path prefix, prepended onto install directories.CMAKE_INSTALL_PREFIX:PATH=/usr/local// Path to a program.DOCBOOK_TO_MAN:FILEPATH=/usr/bin/docbook2x-man// Build man page for xmlwfEXPAT_BUILD_DOCS:BOOL=ON// Build the examples for expat libraryEXPAT_BUILD_EXAMPLES:BOOL=ON// Build fuzzers for the expat libraryEXPAT_BUILD_FUZZERS:BOOL=OFF// Build pkg-config fileEXPAT_BUILD_PKGCONFIG:BOOL=ON// Build the tests for expat libraryEXPAT_BUILD_TESTS:BOOL=ON// Build the xmlwf tool for expat libraryEXPAT_BUILD_TOOLS:BOOL=ON// Character type to use (char|ushort|wchar_t) [default=char]EXPAT_CHAR_TYPE:STRING=char// Install expat files in cmake install targetEXPAT_ENABLE_INSTALL:BOOL=ON// Use /MT flag (static CRT) when compiling in MSVCEXPAT_MSVC_STATIC_CRT:BOOL=OFF// Build fuzzers via OSS-Fuzz for the expat libraryEXPAT_OSSFUZZ_BUILD:BOOL=OFF// Build a shared expat libraryEXPAT_SHARED_LIBS:BOOL=ON// Define to provide symbol versioning for dependency generationEXPAT_SYMBOL_VERSIONING:BOOL=OFF// Treat all compiler warnings as errorsEXPAT_WARNINGS_AS_ERRORS:BOOL=OFF// Make use of getrandom function (ON|OFF|AUTO) [default=AUTO]EXPAT_WITH_GETRANDOM:STRING=AUTO// Make use of syscall SYS_getrandom (ON|OFF|AUTO) [default=AUTO]EXPAT_WITH_SYS_GETRANDOM:STRING=AUTO
About
🌿 Fast streaming XML parser written in C99 with >90% test coverage; moved from SourceForge to GitHub
Topics
Resources
License
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.