Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🌿 Fast streaming XML parser written in C99 with >90% test coverage; moved from SourceForge to GitHub

License

NotificationsYou must be signed in to change notification settings

libexpat/libexpat

Repository files navigation

Run Linux CI tasksPackaging statusDownloads SourceForgeDownloads GitHubOpenSSF Best Practices

Caution

Expat isunderstaffed and without funding.There is acall for help with detailsat the top of theChanges file.

Expat, Release 2.7.4

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.

Using libexpat in your CMake-Based Project

There are three documented ways of using libexpat with CMake:

a)find_package with Module Mode

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)

b)find_package with Config Mode

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)

c) TheFetchContent module

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 theFetchContent module 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)

Building from a Git Clone

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.sh

Once this has been done, follow the same instructions as for buildingfrom a source distribution.

Building from a Source Distribution

a) Building with the configure script (i.e. GNU Autotools)

To build Expat from a source distribution, you first run theconfiguration shell script in the top level distribution directory:

./configure

There 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/mystuff

Another interesting option is to enable 64-bit integer support forline and column numbers and the over-all byte index:

./configure CPPFLAGS=-DXML_LARGE_SIZE

However, 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):

  1. Mass-patchMakefile.am files to uselibexpatw.la for a library name:
    find . -name Makefile.am -exec sed -e 's,libexpat\.la,libexpatw.la,' -e 's,libexpat_la,libexpatw_la,' -i.bak {} +

  2. Runautomake to re-writeMakefile.in files:
    automake

  3. For 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.

  4. Runmake (which excludes xmlwf).

  5. Runmake install (again, excludes xmlwf).

UsingDESTDIR is supported. It works as follows:

make install DESTDIR=/path/to/image

overrides the in-makefile setDESTDIR, because variable-setting priority is

  1. commandline
  2. in-makefile
  3. 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.

b) Building with CMake

The CMake build system is stillexperimental and may replace the primarybuild system based on GNU Autotools at some point when it is ready.

Available Options

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

Stars

Watchers

Forks

Contributors93


[8]ページ先頭

©2009-2026 Movatter.jp