Differences

This shows you the differences between the selected revisions of the page.

logging_xml 2009-03-02 logging_xml 2022-06-16 (current)
Line 1: Line 1:
====== XML Logging ====== ====== XML Logging ======
-XML logging is one of the WinSCP [[logging|log formats]]. XML log includes structured records describing operations done by WinSCP over session. The log format is protocol independent.+XML logging is one of the WinSCP [[logging|log formats]]. An %%XML%% log includes structured records describing operations done by WinSCP over session. The log format is protocol independent.
-===== Purpose ===== +In many cases you do not have to deal with the %%XML%% log file directly. [[library|WinSCP .NET assembly]] can do it for you.
-Primary purpose of the XML logging is to provide machine-readable description of automatically performed operations, such as when using [[scripting|scripting]]. XML logging is useful e.g. to find a list of files that were actually uploaded, when uploading whole directory or files matching a mask.+
-The XML logging is not intended for detection, if batch of operations (such as script file) succeeded or not((Use WinSCP exit code for [[scripting#using_scripting|detection of errors in scripting]])). See [[logging_xml#result|below]].+===== [[purpose]] Purpose ===== 
 +Primary purpose of the XML logging is to provide machine-readable description of automatically performed operations, such as when using [[scripting|scripting]].
-===== Using ===== +The %%XML%% logging is useful e.g. to: 
-XML logging is mostly useful with [[logging|logging to file]] only. Overall format of the XML log file follows:+  * Find a list of files that were actually uploaded/downloaded, when transferring a whole directory or when transferring files matching a mask; 
 +  * Get a directory listing; 
 +  * Record operations done during [[task_synchronize_full|synchronization]]. 
 + 
 +Note that while the %%XML%% logging can be used also for GUI sessions, it does not record [[transfer_queue|background transfers]]. 
 + 
 +===== [[using]] Using ===== 
 +The %%XML%% logging, being used along with [[scripting|scripting]], is most typically enabled from command-line, using ''[[commandline#logging|/xmllog]]'' parameter. It can be enabled in [[ui_pref_logging|preferences]] too. 
 + 
 +An overall format of the %%XML%% log file follows:
<code xml> <code xml>
Line 18: Line 27:
</code> </code>
-The top level ''session'' tag represents one logical session, which may consist of several physical sessions, particularly when connection is lost. Attribute ''name'' refers to name of the logical session. Attribute ''start'' indicates time when the session was initiated·((All timestamps in XML log have XML ''dateTime'' type, where only ''YYYY-MM-DD"T"HH:MM:SS.NNN"Z"'' syntax is used.)).+The top level ''session'' tag represents one logical session, which may consist of several physical sessions, particularly when connection is lost. Attribute ''name'' refers to name of the logical session. Attribute ''start'' indicates time when the session was initiated.((All timestamps in the %%XML%% log have %%XML%% ''dateTime'' type, where only ''%%YYYY-MM-DD"T"HH:MM:SS.NNN"Z"%%'' syntax is used.))
-The ''session'' element includes [[logging_xml#elements|child elements]], where each element represents single log entry, i.e. single physical operation with remote file over the logical session.+The ''session'' element includes [[#elements|child elements]], where each element represents single log entry, i.e. single physical operation with remote file over the logical session.
===== [[operations]] Representing Operations in Log ===== ===== [[operations]] Representing Operations in Log =====
-Every entry in XML log represents single physical operation over the session. Typically this would be an operation with remote file.+Every entry in the %%XML%% log represents single physical operation over the session. Typically this would be an operation with remote file.
Single logical operation (in [[scripting|scripting]] or GUI) may actually involve multiple physical operations, each represented with separate log element. For example [[task_upload|upload]] of file (e.g. using ''put'' scripting command) may be represented by up to three elements, ''upload'' for actual upload, ''touch'' for preserving timestamp and ''chmod'' for preserving permissions. Single logical operation (in [[scripting|scripting]] or GUI) may actually involve multiple physical operations, each represented with separate log element. For example [[task_upload|upload]] of file (e.g. using ''put'' scripting command) may be represented by up to three elements, ''upload'' for actual upload, ''touch'' for preserving timestamp and ''chmod'' for preserving permissions.
-Note that some logical operations does not have corresponding log element (e.g. [[task_link|creation of symbolic link]]). Such operations are omitted from the XML log.+Note that some logical operations does not have corresponding log element (e.g. [[task_link|creation of symbolic link]]). Such operations are omitted from the %%XML%% log.
-===== [[result]] Representing Results/Errors of Operations ===== +===== [[result]] Representing Results/Errors =====
-First, note that the XML logging is not intended for detection, if batch of operations (such as script file) succeeded or not((Use WinSCP exit code for [[scripting#using_scripting|detection of errors in scripting]])). +
-XML log may not include some errors, even if they occur, for two reasons+==== Results/Errors of Operations ==== 
-· * The operation that failed does not have corresponding log element (see [[logging_xml#operations|above]]). +Result of a specific operation is represented by child ''result'' element of respective operation element. The ''result'' element has boolean ''success'' attribute.·
-  * The error is not associated with particular physical operation. Simple example is authentication failure. More treacherous example is failure to list remote directory, to find list of files it contains, while uploading the directory. While this error occurs during upload operation, it is not associated with upload of any particular file. So it will be absent from the XML log. +
- +
-With some protocols, each of the physical operations are performed individually. With some protocols, set of operations may be performed in atomic form. This may prevent mapping error to specific operation. In this case the error may be associated with more operations, resulting in its duplication in the XML log. +
- +
-Result of an operation is represented by child ''result'' element of respective operation element. The ''result'' element has boolean ''success'' attribute.+
<code xml> <code xml>
Line 44: Line 47:
</code> </code>
-If ''success'' is ''false'', ''result'' element will typically include one or more ''message'' elements with error message(s). The error message is free text, that may be language-, protocol- or even server-specific.+If ''success'' is ''false'', ''result'' element will typically include one or more ''message'' elements with error message(s). The error message is free text, that may be language-, protocol- or even server-specific. So you should not try to process it automatically.
 +The following example is from English version, connected with SFTP protocol to OpenSSH server:
<code xml> <code xml>
<result success="false"> <result success="false">
Line 56: Line 60:
</code> </code>
-===== Elements =====+With some protocols, each of the physical operations are performed individually. With some protocols, set of operations may be performed in atomic form. This may prevent mapping error to specific operation. In this case the error may be associated with more operations, resulting in its duplication in the %%XML%% log.
-==== upload ==== +Some errors may not be associated with any operation in the XML log. This particularly happens when: 
-[[task_upload|Upload]] of single file.+  * An error is actually not associated with particular physical operation. Example is invalid script command syntax. 
 +  * The particular operation that failed does not have corresponding log element.  
 + 
 +==== [[result_script]] Results/Errors of Script ==== 
 +When the script fails (WinSCP [[scripting#using_scripting|exit code]] is 1), the top level ''session'' element or ''group'' element (when [[#group|grouping]] is enabled) will include one or more ''failure'' elements, each containing one or more ''message'' elements with error message(s). 
 + 
 +If the particular error was associated with a physical operation, the error message will be included both in ''result'' child element of the respective operation element and in ''failure'' child element of top level ''session'' element or ''group'' element. 
 + 
 +<code xml> 
 +<upload
 + <filename value="d:\examplefile.txt" /> 
 +  <result success="false"> 
 +    <message>Cannot create remote file '/home/user/examplefile.txt'.</message> 
 +    <message>Permission denied. 
 +Error code: 3 
 +Error message from server: Permission denied 
 +Request code: 3</message> 
 +  </result> 
 +</upload> 
 +<failure> 
 +  <message>Cannot create remote file '/home/user/examplefile.txt'.</message> 
 +  <message>Permission denied. 
 +Error code: 3 
 +Error message from server: Permission denied 
 +Request code: 3</message> 
 +</failure> 
 +</code> 
 + 
 +===== [[group]] Grouping Operations for Commands ===== 
 +When using the %%XML%% logging together with [[scripting|scripting]], [[#elements|operations]] and [[#result_script|failures]] belonging to the same command can be grouped using parent ''group'' element: 
 + 
 +<code xml> 
 +<group name="put -preservetime d:\*.txt" start="2021-12-03T14:25:10.204Z"> 
 +  <upload> 
 +    <filename value="d:\readme.txt" /> 
 +    <destination value="/home/user/readme.txt" /> 
 +    <size value="15345" /> 
 +    <result success="true" /> 
 +  </upload> 
 +  <upload> 
 +    <filename value="d:\examplefile.txt" /> 
 +    <result success="false"> 
 +      <message>Cannot create remote file '/home/user/examplefile.txt'.</message> 
 +      <message>Permission denied. 
 +Error code: 3 
 +Error message from server: Permission denied 
 +Request code: 3</message> 
 +    </result> 
 +  </upload> 
 +  <failure> 
 +    <message>Cannot create remote file '/home/user/examplefile.txt'.</message> 
 +    <message>Permission denied. 
 +Error code: 3 
 +Error message from server: Permission denied 
 +Request code: 3</message> 
 +  </failure> 
 +</group> 
 +</code> 
 + 
 +Grouping can be enabled on [[commandline#scripting|command-line]]. 
 + 
 +//Grouping is particularly useful, when you are [[guide_interpreting_xml_log#continuous|continuously reading the XML log file]]. By receiving ''</group>'' you know that the command execution has finished.// 
 + 
 +===== [[elements]] Elements ===== 
 +All operation elements below have ''[[#result|result]]'' child element in addition to listed child elements. 
 + 
 +The ''result'' child element is always present. Many other child elements may be absent in case of error. 
 + 
 +==== [[call]] call ==== 
 +Execution of arbitrary [[remote_command|remote shell command]] (with [[protocols|SFTP and SCP protocols]]) or execution of a protocol command (with FTP protocol). 
 + 
 +Elements: 
 +^ Element                  ^ Description ^ 
 +| ''command''              | Command (in ''value'' attribute) | 
 +| ''destination''          | Absolute path to current remote working directory (in ''value'' attribute) | 
 +| ''output''              | Command standard output (in ''value'' attribute) | 
 +| ''erroroutput''          | Command error output (in ''value'' attribute) | 
 + 
 +Example: 
 +<code xml> 
 +<call> 
 +  <command value="ps" /> 
 +  <destination value="/home/user" /> 
 +  <output value="  PID TTY          TIME CMD 
 +16969 ?        00:00:00 sshd 
 +16970 ?        00:00:00 sftp-server 
 +32647 ?        00:00:00 bash 
 + 1466 ?        00:00:00 ps" /> 
 +  <result success="true" /> 
 +</call> 
 +</code> 
 + 
 +Associated script commands: ''[[scriptcommand_call|call]]'' 
 + 
 +==== [[checksum]] checksum ==== 
 +[[ui_properties#checksum|Calculating a checksum]] of a remote file.  
 + 
 +Elements: 
 +^ Element                  ^ Description ^ 
 +| ''filename''            | Absolute path to a remote file (in ''value'' attribute) | 
 +| ''algorithm''            | Name of a checksum algorithm used (in ''value'' attribute) | 
 +| ''checksum''            | Hex dump of a calculated checksum (in ''value'' attribute) | 
 + 
 +Example: 
 +<code xml> 
 +<checksum> 
 +  <filename value="/home/martin/public_html/index.html" /> 
 +  <algorithm value="sha-1" /> 
 +  <checksum value="bb4dfa9b51d3f6c99b5ec6c12ebf9cade79f43c4" /> 
 +  <result success="true" /> 
 +</checksum> 
 +</code> 
 + 
 +Associated script commands: ''[[scriptcommand_checksum|checksum]]'' 
 + 
 +==== [[chmod]] chmod ==== 
 +[[task_properties|Changing of permissions]] of one (or more) remote file.  
 + 
 +Elements: 
 +^ Element                  ^ Description ^ 
 +| ''filename''            | Absolute path to remote file (in ''value'' attribute) | 
 +| ''permissions''          | Permissions in Unix format ''rwxrwxrwx'' (in ''value'' attribute) | 
 + 
 +With [[scp|SCP protocol]] optional boolean attribute ''recursive'' indicates, if permissions were changed recursively with single operation. 
 + 
 +Example: 
 +<code xml> 
 +<chmod recursive="true"> 
 +  <filename value="/home/martin/public_html/about.html" /> 
 +  <permissions value="rwxr-xr-x" /> 
 +  <result success="true" /> 
 +</chmod> 
 +</code> 
 + 
 +Associated script commands: ''[[scriptcommand_chmod|chmod]]'', ''[[scriptcommand_keepuptodate|keepuptodate]] -permissions'', ''[[scriptcommand_put|put]] -permissions'', ''[[scriptcommand_synchronize|synchronize]] remote|both -permissions'' 
 + 
 +==== [[cp]] cp ==== 
 +[[task_move_duplicate#duplicate|Duplication]] of one remote file or directory.
Elements: Elements:
^ Element                  ^ Description ^ ^ Element                  ^ Description ^
| ''filename''            | Absolute path to source local file (in ''value'' attribute) | | ''filename''            | Absolute path to source local file (in ''value'' attribute) |
-| ''destination''          | Absolute path to destination remote directory (in ''value'' attribute) |+| ''destination''          | Absolute path to destination remote file (in ''value'' attribute) | 
 + 
 +Example: 
 +<code xml> 
 +<cp> 
 +  <filename value="/home/martin/public_html/about.html" /> 
 +  <destination value="/home/martin/backup/about.html.20171220" /> 
 +  <result success="true" /> 
 +</cp> 
 +</code> 
 + 
 +Associated script commands: ''[[scriptcommand_cp|cp]]'' 
 + 
 +==== [[download]] download ==== 
 +[[task_download|Downloading]] of single file. 
 + 
 +Elements: 
 +^ Element                  ^ Description ^ 
 +| ''filename''            | Absolute path to source remote file (in ''value'' attribute) | 
 +| ''destination''          | Absolute path to destination local file (in ''value'' attribute)((File name may differ from name of source file.)) | 
 +| ''size''                | Number of bytes transferred. | 
 + 
 +Example: 
 +<code xml> 
 +<download> 
 +  <filename value="/home/martin/public_html/about.html" /> 
 +  <destination value="d:\www\about.htm" /> 
 +  <size value="55387" /> 
 +  <result success="true" /> 
 +</download> 
 +</code> 
 + 
 +Associated script commands: ''[[scriptcommand_get|get]]'', ''[[scriptcommand_synchronize|synchronize]] local|both'' 
 + 
 +==== [[ls]] ls ==== 
 +Listing of remote directory (only when explicitly requested using ''[[scriptcommand_ls|ls]]'' scripting command). 
 + 
 +Elements: 
 +^ Element                  ^ Description ^ 
 +| ''destination''          | Absolute path to remote directory (in ''value'' attribute)
 +| ''files''                | Container of ''file'' elements | 
 + 
 +Elements of ''file'' element: 
 +^ Element                  ^ Description ^ 
 +| ''filename''            | Name of file without path (in ''value'' attribute) | 
 +| ''type''                | Type of file as in Unix ''ls'' command output, e.g. ''d'' for directory (in ''value'' attribute) | 
 +| ''size''                | Size of file in bytes (in ''value'' attribute) | 
 +| ''modification''        | Modification timestamp (in ''value'' attribute)((All timestamps in the %%XML%% log have %%XML%% ''dateTime'' type, where only ''%%YYYY-MM-DD"T"HH:MM:SS.NNN"Z"%%'' syntax is used.)) | 
 +| ''permissions''          | File permissions in Unix format ''rwxrwxrwx'' (in ''value'' attribute) | 
 +| ''owner''                | File owner (in ''value'' attribute) | 
 +| ''group''                | File group (in ''value'' attribute) | 
 + 
 +Example: 
 +<code xml> 
 +<ls> 
 +  <destination value="/home/martin/public_html" /> 
 +  <files> 
 +    <file> 
 +      <filename value="." /> 
 +      <type value="d" /> 
 +      <modification value="2008-12-22T12:16:23.000Z" /> 
 +      <permissions value="rwxr-xr-x" /> 
 +    </file> 
 +    <file> 
 +      <filename value=".." /> 
 +      <type value="d" /> 
 +      <modification value="2008-03-25T08:15:53.000Z" /> 
 +      <permissions value="rwxr-xr-x" /> 
 +    </file> 
 +    <file> 
 +      <filename value=".htaccess" /> 
 +      <type value="-" /> 
 +      <size value="107" /> 
 +      <modification value="2008-12-02T06:59:58.000Z" /> 
 +      <permissions value="rw-r--r--" /> 
 +    </file> 
 +    <file> 
 +      <filename value="about.html" /> 
 +      <type value="-" /> 
 +      <size value="24064" /> 
 +      <modification value="2007-10-04T21:43:02.000Z" /> 
 +      <permissions value="rw-r--r--" /> 
 +    </file> 
 +  </files> 
 +  <result success="true" /> 
 +</ls> 
 +</code> 
 + 
 +Associated script commands: ''[[scriptcommand_ls|ls]]'' 
 + 
 +==== [[mkdir]] mkdir ==== 
 +[[task_create_directory|Creating of remote directory]]. 
 + 
 +Elements: 
 +^ Element                  ^ Description ^ 
 +| ''filename''            | Absolute path to remote directory (in ''value'' attribute) | 
 + 
 +Example: 
 +<code xml> 
 +<mkdir> 
 +  <filename value="/home/martin/public_html/images" /> 
 +  <result success="true" /> 
 +</mkdir> 
 +</code> 
 + 
 +Associated script commands: ''[[scriptcommand_keepuptodate|keepuptodate]]'', ''[[scriptcommand_mkdir|mkdir]]'', ''[[scriptcommand_put|put]]'', ''[[scriptcommand_synchronize|synchronize]] remote|both'' 
 + 
 +==== [[mv]] mv ==== 
 +[[task_move_duplicate#move|Moving]] of one remote file or directory to different remote directory or [[task_rename|renaming]] of one remote file or directory. 
 + 
 +Elements: 
 +^ Element                  ^ Description ^ 
 +| ''filename''            | Absolute path to source local file (in ''value'' attribute) | 
 +| ''destination''          | Absolute path to destination remote file (in ''value'' attribute)((File name may differ from name of source file.)) | 
 + 
 +Example: 
 +<code xml> 
 +<mv> 
 +  <filename value="/home/martin/public_html/about.html" /> 
 +  <destination value="/tmp/about.bak" /> 
 +  <result success="true" /> 
 +</mv> 
 +</code> 
 + 
 +Associated script commands: ''[[scriptcommand_mv|mv]]'' 
 + 
 +==== [[rm]] rm ==== 
 +[[task_delete|Deleting]] of one (or more) remote file or directory. 
 + 
 +Elements: 
 +^ Element                  ^ Description ^ 
 +| ''filename''            | Absolute path to remote file of directory (in ''value'' attribute) | 
 + 
 +With [[scp|SCP protocol]] optional boolean attribute ''recursive'' indicates, if remote directory was recursively deleted with all contained files with single operation. 
 + 
 +Example: 
 +<code xml> 
 +<rm recursive="true"> 
 +  <filename value="/home/martin/public_html/images" /> 
 +  <result success="true" /> 
 +</rm> 
 +</code> 
 + 
 +Associated script commands: ''[[scriptcommand_get|get]] -delete'', ''[[scriptcommand_keepuptodate|keepuptodate]] -delete'', ''[[scriptcommand_rm|rm]]'', ''[[scriptcommand_rmdir|rmdir]]'', ''[[scriptcommand_synchronize|synchronize]] local|both -delete'' 
 + 
 +==== [[stat]] stat ==== 
 +Listing of remote file attributes. 
 + 
 +Elements: 
 +^ Element                  ^ Description ^ 
 +| ''filename''            | Absolute path to remote file (in ''value'' attribute) | 
 +| ''file''                | Container of file attributes. See specification in description of ''[[#ls|ls]]'' element. Note that ''file'' element within ''stat'' misses ''filename'' subelement, comparing to ''file'' element within ''ls''/''files''. | 
 + 
 +Example: 
 +<code xml> 
 +<stat> 
 +  <filename value="/home/martin/public_html/about.html" /> 
 +  <file> 
 +    <type value="-" /> 
 +    <size value="24064" /> 
 +    <modification value="2007-10-04T21:43:02.000Z" /> 
 +    <permissions value="rw-r--r--" /> 
 +  </file> 
 +  <result success="true" /> 
 +</stat> 
 +</code> 
 + 
 +Associated script commands: ''[[scriptcommand_stat|stat]]'' 
 + 
 +==== [[upload]] upload ==== 
 +[[task_upload|Uploading]] of single file. 
 + 
 +Elements: 
 +^ Element                  ^ Description ^ 
 +| ''filename''            | Absolute path to source local file (in ''value'' attribute) | 
 +| ''destination''          | Absolute path to destination remote file (in ''value'' attribute)((File name may differ from name of source file.)) | 
 +| ''size''                | Number of bytes transferred. |
Example: Example:
<code xml> <code xml>
<upload> <upload>
-  <filename value="d:\www\about.html" /> +  <filename value="d:\www\about.htm" /> 
-  <destination value="/home/martin/public_html/" />+  <destination value="/home/martin/public_html/about.html" /> 
 +  <size value="55387" />
  <result success="true" />   <result success="true" />
</upload> </upload>
</code> </code>
-Associated script commands: ''[[script_commands#keepuptodate|keepuptodate]]'', ''[[script_commands#put|put]]'', ''[[script_commands#synchronize|synchronize]]''+Associated script commands: ''[[scriptcommand_keepuptodate|keepuptodate]]'', ''[[scriptcommand_put|put]]'', ''[[scriptcommand_synchronize|synchronize]] remote|both'' 
 + 
 +==== [[touch]] touch ==== 
 +Changing of remote file timestamp. 
 + 
 +Elements: 
 +^ Element                  ^ Description ^ 
 +| ''filename''            | Absolute path to remote file (in ''value'' attribute) | 
 +| ''modification''        | Modification timestamp (in ''value'' attribute)((All timestamps in the %%XML%% log have %%XML%% ''dateTime'' type, where only ''%%YYYY-MM-DD"T"HH:MM:SS.NNN"Z"%%'' syntax is used.)) | 
 + 
 +Example: 
 +<code xml> 
 +<touch> 
 +  <filename value="/home/martin/public_html/about.html" /> 
 +  <modification value="2008-12-28T11:22:19.000Z" /> 
 +  <result success="true" /> 
 +</touch> 
 +</code> 
 + 
 +Associated script commands: ''[[scriptcommand_keepuptodate|keepuptodate]]'', ''[[scriptcommand_put|put]] -preservetime'', ''[[scriptcommand_synchronize|synchronize]] remote|both'' 
 + 
 +===== Schema ===== 
 +An %%XML%% schema for the %%XML%% log is available at: 
 +http://winscp.net/schema/session/1.0 
 + 
 +===== Example ===== 
 +//Note that the ''[[#group|group]]'' elements will be included, if enabled only.// 
 + 
 +<code xml> 
 +<?xml version="1.0" encoding="UTF-8"?> 
 +<session xmlns="http://winscp.net/schema/session/1.0" 
 +        name="martin@example.com" start="2012-01-04T14:25:53.173Z"> 
 +  <group name="put -preservetime -permissions=644 d:\www\about.htm" start="2012-01-04T14:28:45.393Z"> 
 +    <upload> 
 +      <filename value="d:\www\about.htm" /> 
 +      <destination value="/home/martin/public_html/about.html" /> 
 +      <result success="true" /> 
 +    </upload> 
 +    <touch> 
 +      <filename value="/home/martin/public_html/about.html" /> 
 +      <modification value="2008-12-28T11:22:19.000Z" /> 
 +      <result success="true" /> 
 +    </touch> 
 +    <chmod> 
 +      <filename value="/home/martin/public_html/about.html" /> 
 +      <permissions value="rw-r--r--" /> 
 +      <result success="true" /> 
 +    </chmod> 
 +  </group> 
 +  <group name="rm about.bak" start="2012-01-04T14:28:47.892Z"> 
 +    <rm> 
 +      <filename value="/home/martin/public_html/about.bak" /> 
 +      <result success="false"> 
 +        <message>No such file or directory. 
 +Error code: 2 
 +Error message from server: No such file 
 +Request code: 13</message> 
 +      </result> 
 +    </rm> 
 +    <failure> 
 +      <message>No such file or directory. 
 +Error code: 2 
 +Error message from server: No such file 
 +Request code: 13</message> 
 +    </failure> 
 +  </group> 
 +</session> 
 +</code> 
 + 
 +===== [[parse]] Interpreting/Parsing ===== 
 + 
 +==== General ==== 
 +To parse the %%XML%% log, use any %%XML%% parser available. 
 + 
 +If possible, using [[library|WinSCP .NET assembly]] is the preferred approach, which hides away the %%XML%% log file from your application. 
 + 
 +If you want to parse the XML log yourself anyway, see following guides to learn how to do that in different development environments: 
 +  * [[guide_automation_advanced|*]] (Windows script host; Java or VB script); 
 +  * [[guide_dotnet|*]] (.NET; C# or VB.NET); 
 +  * [[guide_interpreting_xml_log|*]] (.NET, C#). 
 + 
 +==== [[xslt]] Transforming XML Log to Text Output Using XSLT Transformation ==== 
 +You can use XSLT transformation to convert the %%XML%% log to plain text output (or any other format). 
 + 
 +For example to generate a plain text list of successfully downloaded files from the following %%XML%% log (''log.xml''): 
 + 
 +<code xml> 
 +<?xml version="1.0" encoding="UTF-8"?> 
 +<session xmlns="http://winscp.net/schema/session/1.0" name="user@host" start="2021-12-03T06:45:57.008Z"> 
 +  <download> 
 +    <filename value="/path/file1.txt" /> 
 +    <destination value="C:\path\file1.txt" /> 
 +    <size value="2022" /> 
 +    <result success="true" /> 
 +  </download> 
 +  <download> 
 +    <filename value="/path/file2.txt" /> 
 +    <destination value="C:\path\file2.txt" /> 
 +    <size value="5782" /> 
 +    <result success="true" /> 
 +  </download> 
 +</session> 
 +</code> 
 + 
 +use the following %%XSLT%% (''download.xslt''): 
 + 
 +<code xml> 
 +<?xml version="1.0" encoding="UTF-8"?> 
 +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:winscp="http://winscp.net/schema/session/1.0"> 
 +    <xsl:output method="text" encoding="UTF-8"/> 
 +    <xsl:strip-space elements="*"/> 
 +    <xsl:template match='winscp:download[winscp:result[@success="true"]]/winscp:filename'> 
 +        <xsl:value-of select="@value"/> 
 +        <xsl:text>&#xa;</xsl:text> 
 +    </xsl:template> 
 +</xsl:stylesheet> 
 +</code> 
 + 
 +You can execute it using any %%XSLT%% processor: 
 + 
 +  * Microsoft ''msxsl.exe'' (deprecated, but [[https://web.archive.org/web/20200202112313/https://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=21714|available from Internet Archive]]): \\ <code> 
 +msxsl.exe log.xml download.xslt 
 +</code> 
 +  * [[http://xmlsoft.org/|Libxml2]] ''xsltproc.exe'': \\ <code> 
 +xsltproc.exe download.xslt log.xml 
 +</code> 
 + 
 +The output will be: 
 + 
 +<code> 
 +/path/file1.txt 
 +/path/file2.txt 
 +</code> 
 + 
 +For a more complex example, see [[script_custom_listing_format_csv#scripting|*]].

Last modified: by martin