Skip to content

Validate an XML file against an XSD schema using Xerces-C++ and spdlog. 🇰🇷 Xerces-C++ 와 spdlog 를 사용하여 XML 파일을 XSD 스키마로 검증.

License

Notifications You must be signed in to change notification settings

JayTwoLab/xml-xsd-valiator

Repository files navigation

xe_xerces_example

Korean README

Overview

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)

Features

  • XML validation using Xerces-C++
  • Custom SAX2 error handler
  • Logging through spdlog
  • Cross-platform CMake configuration (MSVC, MinGW, Linux)

File Structure

  • main.cpp – entry point
  • xml_validator_app.* – validation controller
  • simple_error_handler.* – SAX2 error handler
  • person_int_schema.xsd – sample schema
  • person_invalid.xml – intentionally invalid sample XML

1. Build Environment Setup

1.1 Windows – Visual Studio (MSVC) + vcpkg

The CMake script assumes vcpkg is installed under %VCPKG_ROOT% or %USERPROFILE%\vcpkg, and uses the triplet x64-windows-static.

  1. Clone and bootstrap vcpkg (PowerShell):

    git clone https://github.com/microsoft/vcpkg.git "$env:USERPROFILE/vcpkg"
    cd "$env:USERPROFILE/vcpkg"
    bootstrap-vcpkg.bat
  2. Install required libraries:

    vcpkg.exe install xerces-c:x64-windows-static spdlog:x64-windows-static
  3. (Optional) Enable user-wide integration:

    vcpkg.exe integrate install
  4. 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.

1.2 Windows – MinGW-w64 (Qt / g++) + vcpkg

For MinGW, the CMake script uses the vcpkg triplet x64-mingw-static, again under %VCPKG_ROOT% or %USERPROFILE%\vcpkg.

  1. 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
  2. Install MinGW-w64 triplet libraries:

    vcpkg.exe install xerces-c:x64-mingw-static spdlog:x64-mingw-static
  3. 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_FILEVCPKG_TARGET_TRIPLET 을 설정하면 CMakeLists.txt 의 MinGW 분기가 자동으로 적용됩니다.

1.3 Linux – Rocky Linux / Ubuntu

On Linux, the project does not use vcpkg. Instead it relies on pkg-config to find system-installed packages xerces-c and spdlog.

1.3.1 Rocky Linux (RHEL)

Install development packages (root or sudo):

sudo dnf install -y     xerces-c-devel     spdlog spdlog-devel     pkgconfig gcc-c++ make

Then configure and build:

cmake -B build
cmake --build build

1.3.2 Ubuntu / Debian

Install development packages:

sudo apt update
sudo apt install -y     libxerces-c-dev     libspdlog-dev     pkg-config g++ make

Then configure and build:

cmake -B build
cmake --build build

2. Basic Build (All Platforms)

Once dependencies are installed and CMake can find Xerces-C++ / spdlog, the build is simply:

cmake -B build
cmake --build build

3. How it Works

  1. Loads XML / XSD paths (from project root)
  2. Initializes Xerces-C++ (once per process)
  3. Configures SAX2 parser with schema checking and XSD location
  4. Parses the XML and collects validation errors through simple_error_handler
  5. Returns an xml_validator_result exit code

About

Validate an XML file against an XSD schema using Xerces-C++ and spdlog. 🇰🇷 Xerces-C++ 와 spdlog 를 사용하여 XML 파일을 XSD 스키마로 검증.

Resources

License

Stars

Watchers

Forks

Packages

No packages published