XmlTools

From OniGalore
Jump to navigation Jump to search
This documentation uses many technical XML-related expressions such as: element, parent element, node, attribute. Therefore it is highly recommended that you have a basic background in XML before using XmlTools or reading its documentation. You'll find a good quick tutorial to familiarize yourself with these terms and XML itself on this page.

XmlTools is a command-line modding tool developed by s10k to operate on XML files, especially those exported by OniSplit. It supports many basic operations, and allows more complex programmable operations through JavaScript. It is written in C++, works in both macOS and Windows, and is currently very efficient in terms of performance.

The initial version was written to help with the development of the Old China level mod and was written in C# previous to v2.0, but later was rewritten in C++ for performance and cross-platform reasons. It was then developed further for the purposes of the AE so that resources could be patched smartly.

XmlTools can be used as a standalone tool or as a base for another tool. It can be issued commands directly on the command-line interface (CLI) or passed a text file on the CLI with a list of commands to perform.

The full documentation for XmlTools' commands is found on the Full documentation subpage.

Links

  • Download the tool here and its dependencies here, or download them together using the AEI's Tools menu.
  • XmlTools is used along with OniSplit as the backend for the GUI modding tool Vago.

Features

  • Update all values in a set of XML elements (e.g., re-position an OBAN animation or adjusting the pelvis height of a TRAM).
  • Inverts a set of XML elements (e.g., reverse the motion of an OBAN animation).
  • Add new values to a set of XML elements (e.g., add the 'unkillable' flag to some characters in a level).
  • Remove values from a set of XML elements (e.g., remove boss shields from characters in a level).
  • Replace values in a set of XML elements (e.g., increase the health of characters by replacing the old HP value).
  • Patch file support that allows the modder to list multiple commands in a file, to all be performed at once.
  • Add new XML inside existing nodes (patch only).
  • Remove XML nodes (patch only).
  • Powerful custom XML editing using JavaScript (e.g., to employ complex logical or mathematical operations) (patch only).
  • To select the elements to which the above operations will apply, you can supply the element name, parent element name, attribute name/value, or an XPath expression.

Syntax

You can see XmlTools' options by supplying the --help option or no option at all. You can get the version with the option --version. The commands below must be preceded by either XmlTools.exe (Windows) or ./XmlTools (Mac). If XmlTools is not in the current folder, you can provide the full/relative path to it or set the path environment variable. On the Mac, be sure to use / rather than \ in paths.

The basic syntax is:

Windows XmlTools.exe --add-values --element-name "Weapon" --new-val "w1_tap" --files "BINACJBOCharacter.xml"
Mac ./XmlTools --add-values --element-name "Weapon" --new-val "w1_tap" --files "BINACJBOCharacter.xml"

Here's how it breaks down:

Invocation Note that if XmlTools is not in the Command Prompt/Terminal's current directory, you must provide the full path to it or set the path environment variable.
Option The command to perform. Note that commands are prefaced by a --; some commands also have a short version which is composed of a single - followed by a letter.
Option Value This is where you supply the value that this specific command needs. As seen below, --element-name requires the XML element name, so we provide that here. Quotes should be used when the value has spaces or to avoid Unix shell expansion.

Command-line operations

You can use any of the following operations with XmlTools. If you don't provide all the required options to an operation, XmlTools will notify you.

Options

-a, --add-values

Adds new values to a set of XML elements;

--remove-values

Removes values from a set of XML elements;

--replace-value

Replaces a specific value in a set of XML elements;

--replace-all-values

Replaces all values in a set of XML elements;

-u, --update-elements

Shifts all values in a set of XML elements by an offset;

-i, --invert-elements

Reverses a set of XML elements.

Input options

-c, --current-val <current-val>

Value to be replaced or removed (use space as separator)

-n, --new-val <new-val>

New value(s) to add or replace current value (use space as separator)

-d, --diff-old-new-val <diff-old-new-val>

Difference to adjust values by, when using --update-values

--positions <positions>

Positions [use space as separator] (zero-based index)

-f, --files <files>

XML files to process (wildcards supported)

-p, --patch-files <patch-files>

Patch files to process (wildcards supported)

--force-target-files <force-target-files>

Force the patch-files operation in the specified XML files (wildcards supported)

-e, --element-name <element-name>

Name of the XML element(s) where processing will occur

--parent-element-name <parent-element-name>

Name of the XML parent element of <element-name> (can be used to filter out elements in different parts of the hierarchy that have duplicate names)

--attribute-name <attribute-name>

Attribute name of <element-name> (used as filter)

--attribute-value <attribute-value>

Attribute value of <attribute-name> (used as filter)

-x, --xpath-expression <xpath-expression>

XPath 1.0 expression (used as filter)

--no-backups

Don't make backups of XML files (faster processing)

--no-verbose

Reduce the number of text messages in output (faster processing)

Patch file operations

Patch files are primarily used to create a list of commands within one file that you can pass to XmlTools to execute all at once, to insert blocks of XML into existing nodes, and to use JavaScript code to modify the XML.

To make a patch, create a plain-text file that uses the following commands and pass it to XmlTools using the patchfile command documented above. See HERE for instructions on making a patch mod package for the AE and HERE to learn how the AEI handles patch mods.

Comments in patch files begin with a '#'.

Commands

Operations in patch files always begin with an '@'. The commands are named in upper case and with words separated by an underscore (_).

@XML_TOOLS

Options for running XmlTools. Right now is only used to specify the minimum version of XmlTools needed for the current patch file.

@ADD_INSIDE_NODES

Adds the following XML to existing XML nodes

@REMOVE_NODES

Removes existing XML nodes

@COMMAND

Runs any of the commands available under "Command-line options" above. Use the usual command-line syntax described in that section.

@CUSTOM_CODE

Executes the following JavaScript code for the purpose of editing the XML. If you are creating a patch mod for the AE, you should try to avoid this operation as much as possible because it is much slower than the native XmlTools commands.

Command options

The values supplied for the following options must always be inside quotes (""). The option names use Pascal case.

Files

Wildcard that matches the file(s) that you want to edit

ElementName

XML element name where processing will occur

ParentElementName

Name of parent element of ElementName (can be used to filter out elements in different parts of the hierarchy that have duplicate names)

AttributeName

XML attribute name of the ElementName (used as filter)

AttributeValue

XML attribute value of the AttributeName (used as filter)

XPathExpression

XPath 1.0 expression (used as filter)

Options

Allows you to name any of the command-line operations. Values must be within " ' " to avoid confusion with the quotes.