This is a Swift package for using XML in Swift (experimental, in development).
It currently uses libxml2 for validation (it uses the implementation from Libxml2Validation for sevaral platforms), and an XML catalog is currently necessary for validation.
Later a validation using Xerces-C++ could be added (binaries for Xerces-C++ are available in XercesBuild), this would be important if one would like to validate against W3C schema.
May 11, 2021: Note that because of the Swift bug SR-14578 you currently have to choose a Swift toolchain for Windows from the Snapshots, which could contain some other errors, as the Snapshots are not as thoroughly tested as the releases. (Some of those problems might result from the fact that the
Foundation library was recently split into into the three libraries
FoundationXML.) With Swift version 5.5 this should be resolved soon.
The Swift Package Manager (SPM) uses symbolic links so you need the SeCreateSymbolicLinkPrivilege privilege to use the SPM on Windows. You could instead activate the Developer Mode on Windows (in the Windows settings, search "Developer" to find the according setting). According to Enable your device for development, Microsoft recommends the Developer Mode for software development. Note that it is possible that the domain policy is overriding the local policy you set.
Install Visual Studio (get it from https://visualstudio.microsoft.com).
Install the Swift toolchain (get it from https://swift.org/download). Swift will be installed to
C:\Library. In a newly opened comamnd line winmdows, the command
swift -version should then print the Swift version.
You will have to make the Windows SDK accessable to Swift. Open the
x64 Native Tools for VS2019 Command Prompt with Administrator rights (via the context menu of the entry for
x64 Native Tools for VS2019 Command Prompt in the start menu) and inside it, execute the following commands. (Please also see the documentation https://swift.org/getting-started/ in case something has changed.)
copy %SDKROOT%\usr\share\ucrt.modulemap "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt\module.modulemap" copy %SDKROOT%\usr\share\visualc.modulemap "%VCToolsInstallDir%\include\module.modulemap" copy %SDKROOT%\usr\share\visualc.apinotes "%VCToolsInstallDir%\include\visualc.apinotes" copy %SDKROOT%\usr\share\winsdk.modulemap "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap"
Different options could be considered for editing Swift source code. We describe the usage of CLion, a commercial IDE. You can get the installer from https://www.jetbrains.com/clion.
Create a new empty directory, and inside it, create a new Swift package by executing the command line
swift package init --type executable in a newly opened command line window. Some files will then be created inside this directory.
Add the Swift plugin via the CLion Settings dialog.
Configure the Swift toolchain in CLion (the settings for the Swift plugin might be the last entry in the Settings dialog). Choose the toolchain under
C:\Library\Developer\Toolchains (select the subdirectory in
Open the Swift package you created in CLion (open
Package.swift in CLion and choose "open as project").
Package.swift add the following inside the dependencies at the top-level of the package:
.package(url: "https://github.com/stefanspringer1/SwiftXML.git", from: "0.0.13"),
For the target, add the following dependency:
.product(name: "SwiftXML", package: "SwiftXML"),
main.swiftin CLion and add the following code (use your paths):
_ = XMLDocument(document: "my path to the XML document", catalog: "my path to the catalog")
The second argument is optional. The argument names might change in later versions. There is an example project SwiftXMLExample to compare to.
Note that, if you want to use a catalog file, an XML catalog is needed here. Also note that paths containing non-ASCII characters might pose a problem at the current state.
swift build -c releasefor building or
swift run -c releasefor also running inside your package. The Swift plugin for CLion is quite new, so this might even be necessary.) With the current state of the project (May 11, 2021) the document should then get validated, validation errors printed, and entity definitions and their usage will be displayed.
|Last commit: 4 weeks ago|