This is a demo for the SwiftXMLParser.
Build with swift build -c release.
Give the path to an XML file as argument to the program and it prints infos about the parts of the XML document the parser finds.
Add the argument "-c" and the elements and all parse events are counted without further output.
Give a second path as second argument to the program and the XML document will be written to this second path.
This demo is published under the Apache License 2.0. For questions or remarks see my contact information on my website.
First we describe how to install Swift on Windows.
- The Swift Package Manager uses symbolic links, but Microsoft has decided that symbolic links might be harmful (see there under "Create symbolic links"). You need the SE_CREATE_SYMBOLIC_LINK privilege in Windows to use symbolic links, you can set this privilege for the user using the
gpedit.msctool (execute as Administrator). (Note that other security policies for your computer might overwrite this setting.) If you have the Home edition of of Windows, you first have to get this tool from Microsoft using the following script (open the command line window as Administrator):
@echo off
pushd "%~dp0"
dir /b %SystemRoot%\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientExtensions-Package~3*.mum >List.txt
dir /b %SystemRoot%\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientTools-Package~3*.mum >>List.txt
for /f %%i in ('findstr /i . List.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i"
pauseYou can then set the privilege in the gpedit.msc tool under Computer Configuration / Windows Settings / Security Settings / Local Policies / User Rights Assignment (use a right-click for the listed setting and choose Properties / Enhanced / Search to add yourself as user). Then restart ypour computer. As a test, try to set a link via mklink LinkFile TargetFile.
-
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 windows, the commandswift -versionshould then print the Swift version. -
You will have to make the Windows SDK accessable to Swift. Open the
x64 Native Tools for VS2019 Command Promptwith Administrator rights (via the context menu of the entry forx64 Native Tools for VS2019 Command Promptin 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"Next, we describe to use this Swift package in the Clion IDE. If you do not want to change this package but only would like to build and run it as-is, instead of using Clion you could just run the command swift build -c release from within the package to build it.
-
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.
-
Start Clion.
-
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 inToolchains). -
Check-out this Swift package and open in in CLion (open
Package.swiftin CLion and choose "open as project"). -
Click the Run symbol in CLion. (You can also execute
swift build -c releasefor building orswift 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.