ReadXML

Get variable from XML file

Related Topics Link IconRelated Topics

Definition

Use this command to read information from existing XML files.
In the dialog box you can specify the information you want to read from a specific XML file (Element, Attribute, Contents).

To identify the editable part of the XML file, DSM uses the specifications of the XML Path Language (XPath) 2.0.
See also: https://www.w3.org/TR/xpath20/

If there are several matches for the part of the XML file you want to edit, you can use an index to specify the match exactly.

The path will be stored in a user-defined, local variable and is valid for the complete installation package and for all other installation packages called by this specific installation package.
Use the contents to change an  XML file with the ModifyXML command, for example.

In case an error occurs when running this command, you can specify the option Stop script on error in the Script Editor. If the error actually occurs, the script stops, thus preventing subsequent errors, and the associated policy is shown as not compliant.
This also applies if you set the package property Error handling to Always terminate script on error (a default setting for new packages).

Settings

Input

  • Entry type
    Select the type of the part of the XML file you want to read:
    • Element - Basic structural unit of an XML file that usually has a tag at the beginning and the end.
      If you search for an element, the result variable contains the complete element with beginning and end tag and the complete contents between the tags.
      Searching for an element returns the complete element, for example: <Object type="STRING">QueenMary</Object>
    • Attribute of an element
      If you search for an attribute, the result variable returns the value of the attribute.
      Searching for the attribute type in the above example element results in: STRING
    • Contents of an element
      If you search for the contents, the result variable contains the complete text contents of the searched element between the beginning and the end tag. This does not include subelements with their text contents.
      Searching for the contents in the above example element results in: QueenMary
  • XML file name
    Path and name of the XML file you want to read. If not specified, the extension .XML is used automatically.
  • XPath query
    Used to identify the part of the XML file you want to read with the help of the XPath syntax.
    Click ... to open the XPath browser for the specified XML file; this browser helps you select the element and converts it to a unique XPath query. Namespaces are also considered. The file is only displayed if the XML file is well-formed.
    In case the respective XML file is not available locally, select an alternative sample file that matches the XML file you want to edit.
    The available options in the XPath  Browser (index-based queries, recursive search) have a direct impact on the XPath query syntax and are based on the specifications of the XML Path Language (XPath) 2.0. Alternatively, you can enter the XPath query manually; in this case, make sure to keep the correct syntax.
    You can use eScript variables with XPath queries.

    XPath query example:
    //Sample/node1/node2/Object[@type="STRING"]
    In this example, the system queries the Object element in Sample/node1/node2 to which the type="STRING" applies.
    In most cases, the system finds several elements that match the query; therefore, specify an Index in addition.
    Find more examples here: ReadXML - Example

  • Attribute name
    This entry provides the name of the queried attribute if you select Entry type = Attribute. You are allowed to use the * wild card.
  • Index
    The index determines which element is to be read if the query finds several matches in the XML file.
    The following options are available:
    • First match(default)
    • Last match
    • Specific Index
      Specify the location of the specific element on the match list, for example 3 for the third incidence in the XML file.
  • Result variable
    Specifies the variable where you want to store the results of the command without %
  • Counter variable
    Specifies the variable where you want to store the index of the used match without %
    You can use this variable to determine the maximum value for the query loop. In this case we recommend that you enter the ReadXML command several times in the eScript: first, to determine the maximum index and second to read the individual values in a corresponding loop.

Options

Disable file direction on x64 computers
For reasons of compatibilty, Ivanti DSM maps file and registry access to the default storage location for 32 bit applications (provided that the storage location differs from that of 64-bit applications). File access: whenever a 32-bit application attempts to access %windir%\System32, the access is redirected to %windir%\SysWOW64. Registry commands: when accessing HKEY_LOCAL_MACHINE\SOFTWARE the calls are redirected to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node. The x64-switch stops this redirection of file and registry accesses when running the script command on a x64 computer; the eScript command runs on the specified path. CallScript command: the script runs in a 64-bit process.