This project demonstrates how to validate an XML file against an XSD schema using Xerces-C++ and spdlog.
The CMakeLists.txt is written to support:
- Windows / MSVC (Visual Studio + vcpkg,
x64-windows-static) - Windows / MinGW-w64 (Qt / g++ + vcpkg,
x64-mingw-static) - Linux (Rocky / Ubuntu, system packages via
pkg-config)
- XML validation using Xerces-C++
- Custom SAX2 error handler
- Logging through spdlog
- Cross-platform CMake configuration (MSVC, MinGW, Linux)
main.cpp– entry pointxml_validator_app.*– validation controllersimple_error_handler.*– SAX2 error handlerperson_int_schema.xsd– sample schemaperson_invalid.xml– intentionally invalid sample XML
The CMake script assumes vcpkg is installed under %VCPKG_ROOT% or %USERPROFILE%\vcpkg, and uses the triplet x64-windows-static.
-
Clone and bootstrap vcpkg (PowerShell):
git clone https://github.com/microsoft/vcpkg.git "$env:USERPROFILE/vcpkg" cd "$env:USERPROFILE/vcpkg" bootstrap-vcpkg.bat
-
Install required libraries:
vcpkg.exe install xerces-c:x64-windows-static spdlog:x64-windows-static
-
(Optional) Enable user-wide integration:
vcpkg.exe integrate install -
Configure & build with CMake (from project root):
cmake -B build -G "Visual Studio 17 2022" -A x64 ^ -DCMAKE_TOOLCHAIN_FILE="$env:USERPROFILE/vcpkg/scripts/buildsystems/vcpkg.cmake" cmake --build build --config Debug
Visual Studio can also open the CMake project directly and will respect the CMAKE_TOOLCHAIN_FILE setting if configured in CMakePresets.json or via the IDE.
For MinGW, the CMake script uses the vcpkg triplet x64-mingw-static, again under %VCPKG_ROOT% or %USERPROFILE%\vcpkg.
-
Clone and bootstrap vcpkg (same location as above):
git clone https://github.com/microsoft/vcpkg.git "$env:USERPROFILE/vcpkg" cd "$env:USERPROFILE/vcpkg" bootstrap-vcpkg.bat
-
Install MinGW-w64 triplet libraries:
vcpkg.exe install xerces-c:x64-mingw-static spdlog:x64-mingw-static
-
Configure & build using MinGW CMake / Qt CMake (example with Qt MinGW kit):
cmake -B build-mingw -G "MinGW Makefiles" ^ -DCMAKE_TOOLCHAIN_FILE=%USERPROFILE%/vcpkg/scripts/buildsystems/vcpkg.cmake ^ -DVCPKG_TARGET_TRIPLET=x64-mingw-static cmake --build build-mingw
Qt Creator에서 MinGW Kit을 선택한 뒤, 위와 동일한 CMAKE_TOOLCHAIN_FILE 과 VCPKG_TARGET_TRIPLET 을 설정하면 CMakeLists.txt 의 MinGW 분기가 자동으로 적용됩니다.
On Linux, the project does not use vcpkg. Instead it relies on pkg-config to find system-installed packages xerces-c and spdlog.
Install development packages (root or sudo):
sudo dnf install -y xerces-c-devel spdlog spdlog-devel pkgconfig gcc-c++ makeThen configure and build:
cmake -B build
cmake --build buildInstall development packages:
sudo apt update
sudo apt install -y libxerces-c-dev libspdlog-dev pkg-config g++ makeThen configure and build:
cmake -B build
cmake --build buildOnce dependencies are installed and CMake can find Xerces-C++ / spdlog, the build is simply:
cmake -B build
cmake --build build- Loads XML / XSD paths (from project root)
- Initializes Xerces-C++ (once per process)
- Configures SAX2 parser with schema checking and XSD location
- Parses the XML and collects validation errors through
simple_error_handler - Returns an
xml_validator_resultexit code