Set-XmlNode

This command adds new entries to an XML file or changes or deletes existing entries. The modified file is only saved if it is a "well-formed" XML file, but the schema is not validated.

In the dialog box you specify which information of the XML file is to be edited (element, attribute, content). For elements only adding or deleting is possible, for attributes and content also changing is available.

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

If the search for the part of the XML file to be edited finds several hits, you can use an index to determine the exact hit you are looking for.

Note: Starting with version 3.0 of the PPB, the Set-XmlNode command can also be generated by dragging and dropping XML files (*.xml) into the script window. If the files are already in the package directory, the source path is referenced relatively with .\, if the source files are outside the package directory, the full path is taken.


Settings:

  • Entry type
    Selection of the type of the part of the XML file to be edited:
    • Element - Basic structural unit of an XML file, which usually has a start and end tag.
      If an element is to be deleted, the element identified under XPath query is completely deleted with all subelements and contents. If a new element is to be added, the content of the Entry value field is added to the XML file under the specified element.
      If no XPath query is specified, the content of the Entry value field is used to replace the full content of the XML file. This is how you can create a new XML file.
    • Attribute of an element
      If an attribute is to be deleted, the attribute is completely deleted from the element identified under XPath query.
      If an attribute is to be added or changed, the attribute is entered in the identified element. The command automatically detects if the attribute already exists and reacts accordingly. 
    • Content of an element - this refers to the text content of an element between the start and end tag (without sub-elements)
      If the content of an element is to be deleted, it is completely deleted from the element identified under XPath query.
      If the content of an element is to be added or changed, the content is entered into the identified element or replaces the existing content. Subelements are not treated as content and are therefore ignored.
  • Action
    The following actions are available:
    • Add
    • Change 
      This action is not available for the type element. If an attribute or content to be changed does not exist, it is added.
    • Delete
  • XML file name
    XML file to be modified. The use of variables is possible. Use the "..." button to select an existing file (on the packaging system) or enter the path manually.
  • XPath query
    Identification of the part of the XML file to be edited using XPath syntax. With a click on the "..." button you open the XPath browser for the specified XML file, which enables a convenient selection of the searched element including its conversion into a unique XPath query. Namespaces are also taken into account. The file is only displayed if it is a "well-formed" XML file.

    If the XML file in question is not available locally, select an alternative sample file that should correspond to the XML file to be edited. 

    The options offered in the XPath browser (index-based query, recursive search) directly influence the syntax of the XPath query and are based on the XML Path Language (XPath) 2.0 specifications. Alternatively, you can enter the XPath query manually, but in this case you must ensure that the syntax is adhered to yourself.

    The XPath query allows the use of variables
  • Index
    Defines which elements should be processed if the query returns multiple hits in the XML file. The following elements are available for selection:
    • All machtes (Default)
    • First match
    • Last match
    • Specific index
      To do this, you must specify the position of the desired element in the hit list, e.g. 3 for the third occurrence in the XML file. If necessary, use the command Read-XmlNode to determine the desired index value.
  • Attribute name
    Contains the name of the attribute searched for if Entry type = attribute was selected. The placeholder * is allowed.
  • Entry value
    Defines the XML content to be replaced or added to the XML file for the Add and Change actions. To enter complex and multi-line contents, open the XML file by clicking on the "..." button to open an editor. The use of variables is possible. 
  • Use 32-Bit mode on x64 computer
    If the script is executed on a 64-bit operating system, the counterpart for 32-bit applications SysWOW64 can be used automatically when referring to the SYSTEM32 directory.


Example:

The example here changes the log path in the App Deployment Toolkit configuration file.


Corresponds to DSM eScript command:

  • ModifyXML


See also: