XmlTools: Difference between revisions

From OniGalore
Jump to navigation Jump to search
m (using hatnote template)
 
(55 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{finish}}
{{Hatnote|This documentation uses many technical [[wp:XML|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 [https://www.w3schools.com/xml/xml_whatis.asp on this page].}}
XmlTools is a command-line modding tool developed by [[User:Script 10k|s10k]] to operate on XML files, especially those exported by [[OniSplit#XML|OniSplit]]. It supports many basic operations, and allows more complex programmable operations through [[wp:JavaScript|JavaScript]]. It is written in C++, works in both macOS and Windows, and is currently very efficient in terms of performance.


==Overview==
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 is a command-line modding tool that operates on XML files, especially those exported by [[OniSplit#XML|OniSplit]]. It was developed in C# and works in both Mac OS X (Mono required) and Windows (.NET required).


The initial version was written to help with the development of the Old China level mod. It was then developed further for the purposes of the [[AE]].
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.


It can be used as a standalone tool or as a base for another tools.
The full documentation for XmlTools' commands is found on the [[XmlTools/Full documentation|Full documentation]] subpage.


==Links==
==Links==
*Download the tool package [http://mods.oni2.net/node/224 here] (actual program folder found inside the plain/xxx_only/Tools/ folder).
*Download the tool [http://mods.oni2.net/node/265 here] and its dependencies [http://mods.oni2.net/node/304 here], or download them together using the [[AEI]]'s Tools menu.
*XmlTools is used by the [[AEI]] to apply [[Making a patch mod|XML patches]], as explained [[Anniversary Edition/Framework#XML patching|HERE]].
*XmlTools is used along with OniSplit as the backend for the GUI modding tool [[Vago_(tool)|Vago]].
*XmlTools is used along with OniSplit as the backend for the GUI tool [[Vago_(tool)|Vago]].


==Features==
==Features==
*'''Modify a chain of values''' (for example, to reposition an OBAN animation or adjust pelvis height for a TRAM).
*'''Update all values in a set of XML elements''' (e.g., re-position an OBAN animation or adjusting the pelvis height of a TRAM).
*'''Invert a chain of values''' (for example, invert an OBAN animation).
*'''Inverts a set of XML elements''' (e.g., reverse the motion of an OBAN animation).
*'''Add new values to XML elements''' (for example, add the 'unkillable' flag to some characters in a level).
*'''Add new values to a set of XML elements''' (e.g., add the 'unkillable' flag to some characters in a level).
*'''Remove values from XML elements''' (for example, remove boss shields from 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 XML elements''' (for example, increase the health of characters by replacing the old HP value).
*'''Replace values in a set of XML elements''' (e.g., increase the health of characters by replacing the old HP value).
*'''Add custom XML to existing files (patch only)'''
*'''Patch file support''' that allows the modder to list multiple commands in a file, to all be performed at once.
*'''Remove XML from existing files (patch only)'''
*'''Add new XML inside existing nodes''' (patch only).
*'''Patch file support''' allows the modder to list multiple commands in a file, on separate lines, to all be performed at once.
*'''Remove XML nodes''' (patch only).
*'''Powerful custom XML editing using JavaScript''' (e.g., to employ complex logical or mathematical operations) (patch only).


==Using it==
* 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'''.
The following actions are listed when calling XmlTools with no options passed in. You can get the version with the argument "version".
:The commands below must be preceded by either <tt>xmlTools.exe</tt> (Windows) or <tt>mono xmlTools.exe</tt> (Mac)
::If xmlTools.exe is not in the current folder, you can provide the full/relative path to it or set the path variable.
:::On the Mac, be sure to use / rather than \ in paths. The following instructions are for Windows by default.


===Global arguments===
==Syntax==
You may use these arguments with each command listed in the next section:
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 <tt>XmlTools.exe</tt> (Windows) or <tt>./XmlTools</tt> (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 <tt>/</tt> rather than <tt>\</tt> in paths.
 
The basic syntax is:
{|
{|
|<tt>-filename:<XML file></tt>||Specifies file to modify (allows wildcards '*','?') (backup made by default) (when not used will apply the operation over all the xml files in the same directory of xmlTools.exe)||'''Optional'''
|-
|-
|<tt>-element:<XML tag></tt>||Specifies XML tag to look for in the file||'''Required'''
|'''Windows'''||<tt><span style="background:rgb(235,235,235); border-radius:0.33em;">XmlTools.exe</span> <span style="background:rgb(175,175,255); border-radius:0.33em;">--add-values</span> <span style="background:rgb(175,175,255); border-radius:0.33em;">--element-name</span> <span style="background:rgb(156,255,156); border-radius:0.33em;">"Weapon"</span> <span style="background:rgb(175,175,255); border-radius:0.33em;">--new-val</span> <span style="background:rgb(156,255,156); border-radius:0.33em;">"w1_tap"</span> <span style="background:rgb(175,175,255); border-radius:0.33em;">--files</span> <span style="background:rgb(156,255,156); border-radius:0.33em;">"BINACJBOCharacter.xml"</span></tt>
|-
|-
|<tt>-parelement:<XML tag></tt>||Specifies XML tag that contains -element tag to avoid override elements that have the same name but have different parent elements ||'''Optional'''
|'''Mac'''||<tt><span style="background:rgb(235,235,235); border-radius:0.33em;">./XmlTools</span> <span style="background:rgb(175,175,255); border-radius:0.33em;">--add-values</span> <span style="background:rgb(175,175,255); border-radius:0.33em;">--element-name</span> <span style="background:rgb(156,255,156); border-radius:0.33em;">"Weapon"</span> <span style="background:rgb(175,175,255); border-radius:0.33em;">--new-val</span> <span style="background:rgb(156,255,156); border-radius:0.33em;">"w1_tap"</span> <span style="background:rgb(175,175,255); border-radius:0.33em;">--files</span> <span style="background:rgb(156,255,156); border-radius:0.33em;">"BINACJBOCharacter.xml"</span></tt>
|}
|}
e.g.:
<pre>
<xml>
    <Volume>
          <Min>1</Min>
          <Max>1</Max>
    </Volume>
    <Pitch>
          <Min>1</Min>
          <Max>1</Max>
    </Pitch>
<xml>
</pre>
In the above code you can differentiate the "Min" elements by it's parent element. So you can use -element:Min -parelement:Pitch to refer to "Min" of "Pitch" element.


Here's how it breaks down:
{|
{|
! style="width:130px"|
|- valign="top"
|<span style="background:rgb(235,235,235); border-radius:0.33em;">'''Invocation'''</span>
|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.
|-
|-
|<tt>-nobackups</tt>||XmlTools will not create a backup file (speeds up operations)||'''Optional'''
|<span style="background:rgb(175,175,255); border-radius:0.33em;">'''Option'''</span>||The command to perform. Note that commands are prefaced by a <tt>--</tt>; some commands also have a short version which is composed of a single <tt>-</tt> followed by a letter.
|-
|-
|<tt>-debug</tt>||Not used yet. It will be probably used to output some debugging information in the future.||'''Optional'''
|<span style="background:rgb(156,255,156); border-radius:0.33em;">'''Option Value'''</span>||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 [https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_04.html Unix shell expansion].
|- valign="top"
|}
|}


===Command-line operations===
==Command-line operations==
<tt>updatechainvalues -newvalue:<quoted string> [-valpositions:<quoted string>] [-valrelation:<quoted string>]</tt>
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.
:Update a XML chain, starting at the -newvalue;
 
:<tt>-valpositions</tt> (optional) is zero-indexed and can be a single value or a space-separated list, e.g. <tt>-valpositions=0 1 4</tt>;
===Options===
:<tt>-valrelation</tt> (optional) means ???
<tt>[[XmlTools/Full_documentation#--add-values|-a, --add-values]]</tt>
:Adds new values to a set of XML elements;
 
<tt>[[XmlTools/Full_documentation#--remove-values|--remove-values]]</tt>
:Removes values from a set of XML elements;
 
<tt>[[XmlTools/Full_documentation#--replace-value|--replace-value]]</tt>
:Replaces a specific value in a set of XML elements;
 
<tt>[[XmlTools/Full_documentation#--replace-all-values|--replace-all-values]]</tt>
:Replaces all values in a set of XML elements;
 
<tt>[[XmlTools/Full_documentation#--update-elements|-u, --update-elements]]</tt>
:Shifts all values in a set of XML elements by an offset;
 
<tt>[[XmlTools/Full_documentation#--invert-elements|-i, --invert-elements]]</tt>
:Reverses a set of XML elements.
 
===Input options===
<tt>-c, --current-val <current-val></tt>
:Value to be replaced or removed (use space as separator)
 
<tt>-n, --new-val <new-val></tt>
:New value(s) to add or replace current value (use space as separator)
 
<tt>-d, --diff-old-new-val <diff-old-new-val></tt>
:Difference to adjust values by, when using '''--update-values'''
 
<tt>--positions <positions></tt>
:Positions [use space as separator] (zero-based index)
 
<tt>-f, --files <files></tt>
:XML files to process (wildcards supported)
 
<tt>-p, --patch-files <patch-files></tt>
:Patch files to process (wildcards supported)
 
<tt>--force-target-files <force-target-files></tt>
:Force the patch-files operation in the specified XML files (wildcards supported)
 
<tt>-e, --element-name <element-name></tt>
:Name of the XML element(s) where processing will occur
 
<tt>--parent-element-name <parent-element-name></tt>
: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)
 
<tt>--attribute-name <attribute-name></tt>
:Attribute name of <element-name> (used as filter)
 
<tt>--attribute-value <attribute-value></tt>
:Attribute value of <attribute-name> (used as filter)
 
<tt>-x, --xpath-expression <xpath-expression></tt>
:[https://www.w3.org/TR/1999/REC-xpath-19991116/ XPath 1.0] expression (used as filter)
 
<tt>--no-backups</tt>
:Don't make backups of XML files (faster processing)
 
<tt>--no-verbose</tt>
:Reduce the number of text messages in output (faster processing)


<tt>invert</tt>
==Patch file operations==
:Inverts a XML chain
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.


<tt>addvalue -value:<quoted string></tt>
To make a patch, create a plain-text file that uses the following commands and pass it to XmlTools using the <tt>patchfile</tt> command documented above. See [[Making a patch mod|HERE]] for instructions on making a patch mod package for the AE and [[Anniversary Edition/Framework#Installation|HERE]] to learn how the [[AEI]] handles patch mods.
:Adds value or space-separated list of values into an element


<tt>removevalue -value:<quoted string></tt>
Comments in patch files begin with a '#'.
:Removes value or space-separated list of values from an element


<tt>replacevalue -oldvalue:<string> -newvalue:<string></tt>
===Commands===
:Replaces specified old value, if found, with new value
Operations in patch files always begin with an '@'. The commands are named in upper case and with words separated by an underscore (_).


<tt>replaceall -value:<string> [-valpositions:<quoted string>]</tt>
<tt>[[XmlTools/Full_documentation#.40XML_TOOLS|@XML_TOOLS]]</tt>
:Replaces value in element with new value, no matter its previous value
:Options for running XmlTools. Right now is only used to specify the minimum version of XmlTools needed for the current patch file.


<tt>showerrtypes</tt>
<tt>[[XmlTools/Full_documentation#.40ADD_INSIDE_NODES|@ADD_INSIDE_NODES]]</tt>
:Show errors numbers and they internal name
:Adds the following XML to existing XML nodes


<tt>patchfile [-forceinfiles:<file names>]</tt>
<tt>[[XmlTools/Full_documentation#.40REMOVE_NODES|@REMOVE_NODES]]</tt>
:Changes <tt>-filename</tt> argument to refer to a patch file and applies this patch to the specified files using the [File<quoted file name>] argument,
:Removes existing XML nodes
:or to named files with <tt>-forceinfiles</tt> argument (allows wildcards '*','?'); see below for patch commands


===Patch file operations===
<tt>[[XmlTools/Full_documentation#.40COMMAND|@COMMAND]]</tt>
To create a list of commands within one file that you can pass to XmlTools to execute all at once, create a plain-text file that uses the following commands and pass it to XmlTools using the <tt>patchfile</tt> command documented above. See [[Making a patch mod|HERE]] for instructions on making a patch mod for the AE.
:Runs any of the commands available under "Command-line options" above. Use the usual command-line syntax described in that section.


<tt>@ADDTO Element <quoted tag name> [ParentElement <quoted tag name>] [File<quoted file name>]</tt>
<tt>[[XmlTools/Full_documentation#.40CUSTOM_CODE|@CUSTOM_CODE]]</tt>
:Adds the raw XML that follows to the named array tag, e.g.:
:Executes the following JavaScript code for the purpose of editing the XML. If you are creating a patch mod for the AE, <u>you should try to avoid this operation as much as possible</u> because it is much slower than the native XmlTools commands.
@ADDTO Element "Particles"
<xml>
    <Particle>
      <Start>0</Start>
      <End>45</End>
      <Bone>Head</Bone>
      <Name>glass_break</Name>
    </Particle>
</xml>


<tt>@REMOVE Element <quoted tag name> [ParentElement <quoted tag name>] [File<quoted file name>]</tt>
===Command options===
:Removes named element from the array tag named by ParentElement
The values supplied for the following options must <u>always</u> be inside quotes (""). The option names use [http://wiki.c2.com/?PascalCase Pascal case].


<tt>@COMMAND <command-line string></tt>
<tt>Files</tt>
:Runs any of the commands available under "Command-line operations" above. Use standard command-line syntax described in that section, including <tt>-filename</tt>, e.g.:
:[https://www.computerhope.com/jargon/w/wildcard.htm Wildcard] that matches the file(s) that you want to edit
@COMMAND invert -element:Height -parelement:Heights -filename:test.xml


<tt>@CUSTOMCODE [File<quoted file name>]</tt>
<tt>ElementName</tt>
:Executes the [http://en.wikipedia.org/wiki/JavaScript javascript] code inside the code tag, useful for complex XML editing (using loops and conditions for example). <u>You should avoid this method</u> because it is much more slower than the native XmlTools commands, so always which is possible edit your code using XmlTools commands.
:XML element name where processing will occur
:The XML library that you can use in javascript code is called ''W3C DOM Parser'' and its documentation is available [http://xmljs.sourceforge.net/website/documentation-w3cdom.html here].
:The current file XML is saved at the global variable ''$xmlData''. So you will need to access it to edit the XML. Make sure that after the editing process you update ''$xmlData'' with the new XML so the file gets correctly edited.
: Usage example:


<tt>ParentElementName</tt>
:Name of parent element of ElementName (can be used to filter out elements in different parts of the hierarchy that have duplicate names)


XML code:
<tt>AttributeName</tt>
<Oni>
:XML attribute name of the ElementName (used as filter)
  <Animation>
    <Lookup>
      <Type>KickForward</Type>
      <AimingType>KickForward</AimingType>
      <FromState>RunBackStart</FromState>
      <ToState>Standing</ToState>
      <Varient>Combat</Varient>
      <FirstLevel>4</FirstLevel> <span style="color:#008000"><nowiki><!--</nowiki> The bellow javascript code will change the FirstLevel tag value from 4 to 0 --></span>
      ...
      </Lookup>
  </Animation>
</Oni>


<tt>AttributeValue</tt>
:XML attribute value of the AttributeName (used as filter)


Javascript code:
<tt>XPathExpression</tt>
@CUSTOMCODE
:[http://zvon.org/comp/r/tut-XPath_1.html#intro XPath 1.0] expression (used as filter)
<nowiki><code></nowiki>
  var parser = new DOMImplementation(); <span style="color:#008000">// instantiate the W3C DOM Parser</span>
  var domDoc = parser.loadXML($xmlData); <span style="color:#008000">// load the XML into the parser and get the DOMDocument, using $xmlData variable</span>
  var levelNode=domDoc.getDocumentElement().getElementsByTagName("FirstLevel").item(0).firstChild;
  if(levelNode.toString() == "4"){
      levelNode.setNodeValue("0"); <span style="color:#008000">// Change level from 4 to 0</span>
  }
  $xmlData=domDoc.getDocumentElement().getXML(); <span style="color:#008000">// update the global variable with the new XML</span>
<nowiki></code></nowiki>
Note that if you don't specify the optional [File<quoted file name>] argument the operation will applied over all the XML files in the same directory of xmlTools.exe.


Also this [File<quoted file name>] allows wildcards ('*','?').
<tt>Options</tt>
:Allows you to name any of the [[#Command-line_operations|command-line operations]]. Values must be within " ' " to avoid confusion with the quotes.


[[Category:Bi-platform modding tools]][[Category:Completed modding tools]]
[[Category:Bi-platform modding tools]][[Category:Completed modding tools]][[Category:Modding tutorials]]

Latest revision as of 21:52, 2 July 2022

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.