Jump to content

XmlTools: Difference between revisions

198 bytes added ,  16 March 2016
grammar edit and some wiki touch-up
m (→‎Features: typo)
(grammar edit and some wiki touch-up)
Line 1: Line 1:
==XML Background==
:''This documentation uses many technical [[wikipedia:XML|XML]]-related expressions such as: element, parent element, node, attribute. Because of this, 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 [http://www.w3schools.com/xml/xml_whatis.asp on this page].''


This documentation uses many [[wikipedia:XML|XML]] technical expressions such as: element, parent element, node, attribute. Because of this it is highly recommended that you have a basic background of XML before using XmlTools or any of its documentation.
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 [[wikipedia:JavaScript|JavaScript]]. It is written in C++, works in both Mac OS X and Windows, and is currently very efficient in terms of performance.


You can get a rapid and good tutorial to get familiar with this expressions and XML itself [http://www.w3schools.com/xml/xml_whatis.asp in this page].
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.  


==Overview==
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.
XmlTools is a command-line modding tool that operates on XML files, including those exported by [[OniSplit#XML|OniSplit]]. It supports many operations in XML files and even non implemented operations using custom javascript code.  


It is written in C++, works in both Mac OS X and Windows and is currently very efficient in terms of performance.
The full documentation for XmlTools' commands is found on the [[XmlTools/Full documentation|Full documentation]] subpage.
 
The initial version was written to help with the development of the Old China level mod and was also written in C# (previous 2.0) but later it was rewritten to C++ due to performance reasons and cross platform problems. It was then developed further for the purposes of the [[AE]] so that resources could be patched smartly. To learn about the overall process, read [[Making a patch mod]] and [[Anniversary Edition/Framework#XML patching|AE Framework - XML patching]].
 
XmlTools can be used as a standalone tool or as a base for another tools. 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.
 
Aditional documentation for XmlTools can be found in [[XmlTools/Full documentation]].


==Links==
==Links==
*Download the tool [http://mods.oni2.net/node/265 here] and its dependencies [http://mods.oni2.net/node/304 here] or download them all using the [[AEI]].
*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 along with OniSplit as the backend for the GUI tool [[Vago_(tool)|Vago]].
*XmlTools is used along with OniSplit as the backend for the GUI modding tool [[Vago_(tool)|Vago]].


==Features==
==Features==
*'''Update all values in a set of XML elements''' (e.g., repositioning an OBAN animation or adjusting the pelvis height of 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).
*'''Inverts a set of XML elements''' (e.g., invert an OBAN animation).
*'''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).
*'''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).
*'''Remove values from a set of XML elements''' (e.g., remove boss shields from characters in a level).
Line 29: Line 22:
*'''Add new XML inside existing nodes''' (patch only).
*'''Add new XML inside existing nodes''' (patch only).
*'''Remove XML nodes''' (patch only).
*'''Remove XML nodes''' (patch only).
*'''Powerful custom XML editing using [[wikipedia:JavaScript|JavaScript]]''' (e.g., to employ complex logical or mathematical operations) (patch only).
*'''Powerful custom XML editing using JavaScript''' (e.g., to employ complex logical or mathematical operations) (patch only).


* To select elements to the above operations it can be used the '''element name, parent element name, attribute name/value and [http://www.w3.org/TR/xpath/ XPath 1.0]'''.
* 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==
==Syntax==
You can find out the XmlTools options if you don't provide any or when using --help option. 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 variable. On the Mac, be sure to use <tt>/</tt> rather than <tt>\</tt> in paths.
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:
The basic syntax is:
Line 49: Line 42:
|- valign="top"
|- valign="top"
|<span style="background:rgb(235,235,235); border-radius:0.33em;">'''Invocation'''</span>
|<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 variable.
|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.
|-
|-
|<span style="background:rgb(175,175,255); border-radius:0.33em;">'''Option'''</span>||The command to perform. Note the commands are prefaced by a <tt>--</tt>, some commands have a short version which is prefaced by a single <tt>-</tt> followed by a letter.
|<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.
|-
|-
|<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 [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_04.html Unix shell expansion].
|<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 [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_04.html Unix shell expansion].
|- valign="top"
|- valign="top"
|}
|}


==Command-line operations==
==Command-line operations==
You can use any of the following operations bellow with XmlTools. If you don't provide all the required options to an operation XmlTools will notice you.
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===
===Options===
<tt>[[XmlTools/Full_documentation#--add-values|-a, --add-values]]</tt>
<tt>[[XmlTools/Full_documentation#--add-values|-a, --add-values]]</tt>
:Add new values to a set of XML elements;
:Adds new values to a set of XML elements;


<tt>[[XmlTools/Full_documentation#--remove-values|--remove-values]]</tt>
<tt>[[XmlTools/Full_documentation#--remove-values|--remove-values]]</tt>
Line 68: Line 61:


<tt>[[XmlTools/Full_documentation#--replace-value|--replace-value]]</tt>
<tt>[[XmlTools/Full_documentation#--replace-value|--replace-value]]</tt>
:Replaces 1 value in a set of XML elements;
:Replaces a specific value in a set of XML elements;


<tt>[[XmlTools/Full_documentation#--replace-all-values|--replace-all-values]]</tt>
<tt>[[XmlTools/Full_documentation#--replace-all-values|--replace-all-values]]</tt>
Line 74: Line 67:


<tt>[[XmlTools/Full_documentation#--update-elements|-u, --update-elements]]</tt>
<tt>[[XmlTools/Full_documentation#--update-elements|-u, --update-elements]]</tt>
:Updates all values in a set of XML elements;
:Shifts all values in a set of XML elements by an offset;


<tt>[[XmlTools/Full_documentation#--invert-elements|-i, --invert-elements]]</tt>
<tt>[[XmlTools/Full_documentation#--invert-elements|-i, --invert-elements]]</tt>
:Inverts a set of XML elements.
:Reverses a set of XML elements.


===Input Options===
===Input options===
<tt>-c, --current-val <current-val></tt>
<tt>-c, --current-val <current-val></tt>
:Current value(s) [use space as separator];
:Value to be replaced or removed (use space as separator)


<tt>-n, --new-val <new-val></tt>
<tt>-n, --new-val <new-val></tt>
:New value(s) [use space as separator];
:New value(s) to add or replace current value (use space as separator)


<tt>-d, --diff-old-new-val <diff-old-new-val></tt>
<tt>-d, --diff-old-new-val <diff-old-new-val></tt>
:Difference between old and new value;
:Difference to adjust values by, when using '''--update-values'''


<tt>--positions <positions></tt>
<tt>--positions <positions></tt>
:Positions [use space as separator] [0-index based];
:Positions [use space as separator] (zero-based index)


<tt>-f, --files <files></tt>
<tt>-f, --files <files></tt>
:XML files to process [wildcards supported];
:XML files to process (wildcards supported)


<tt>-p, --patch-files <patch-files></tt>
<tt>-p, --patch-files <patch-files></tt>
:Patch files to process [wildcards supported];
:Patch files to process (wildcards supported)


<tt>--force-target-files <force-target-files></tt>
<tt>--force-target-files <force-target-files></tt>
:Force the patch-files operation in the specified XML files. [wildcards supported];
:Force the patch-files operation in the specified XML files (wildcards supported)


<tt>-e, --element-name <element-name></tt>
<tt>-e, --element-name <element-name></tt>
:Name of the XML element(s) where processing will occur;
:Name of the XML element(s) where processing will occur


<tt>--parent-element-name <parent-element-name></tt>
<tt>--parent-element-name <parent-element-name></tt>
:Name of the XML parent element of <element-name> [used as filter];
: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>
<tt>--attribute-name <attribute-name></tt>
:Attribute name of <element-name> [used as filter];
:Attribute name of <element-name> (used as filter)


<tt>--attribute-value <attribute-value></tt>
<tt>--attribute-value <attribute-value></tt>
:Attribute value of <attribute-name> [used as filter];
:Attribute value of <attribute-name> (used as filter)


<tt>-x, --xpath-expression <xpath-expression></tt>
<tt>-x, --xpath-expression <xpath-expression></tt>
:[http://www.w3.org/TR/xpath/ XPath 1.0] expression to select elements where processing will occur;
:[http://www.w3.org/TR/xpath/ XPath 1.0] expression (used as filter)


<tt>--no-backups</tt>
<tt>--no-backups</tt>
:No backups [faster processing];
:Don't make backups of XML files (faster processing)


<tt>--no-verbose</tt>
<tt>--no-verbose</tt>
:Reduce the number of text messages output [faster processing].
:Reduce the number of text messages in output (faster processing)


==Patch file operations==
==Patch file operations==
Patch files are mainly used for two purposes: to create a list of commands within one file that you can pass to XmlTools to execute all at once, to remove XML nodes, to insert new XML nodes and to use [[wikipedia:JavaScript|JavaScript]] code to modify the XML.
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 [[wikipedia:JavaScript|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 <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#XML patching|HERE]] to learn how the [[AEI]] handles patch mods.
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#XML patching|HERE]] to learn how the [[AEI]] handles patch mods.


Comments in patch files begin with '#'.
Comments in patch files begin with a '#'.
 
===Options===


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


<tt>[[XmlTools/Full_documentation#.40XML_TOOLS|@XML_TOOLS]]</tt>
<tt>[[XmlTools/Full_documentation#.40XML_TOOLS|@XML_TOOLS]]</tt>
:XmlTools information. Right now is only used to specify the executable minimum version for the current patch file;
:Options for running XmlTools. Right now is only used to specify the minimum version of XmlTools needed for the current patch file.


<tt>[[XmlTools/Full_documentation#.40ADD_INSIDE_NODES|@ADD_INSIDE_NODES]]</tt>
<tt>[[XmlTools/Full_documentation#.40ADD_INSIDE_NODES|@ADD_INSIDE_NODES]]</tt>
:Adds new XML nodes;
:Adds the following XML to existing XML nodes


<tt>[[XmlTools/Full_documentation#.40REMOVE_NODES|@REMOVE_NODES]]</tt>
<tt>[[XmlTools/Full_documentation#.40REMOVE_NODES|@REMOVE_NODES]]</tt>
:Removes existing XML nodes;
:Removes existing XML nodes


<tt>[[XmlTools/Full_documentation#.40COMMAND|@COMMAND]]</tt>
<tt>[[XmlTools/Full_documentation#.40COMMAND|@COMMAND]]</tt>
:Runs any of the commands available under "Command-line options" above. Use standard command-line syntax described in that section;
:Runs any of the commands available under "Command-line options" above. Use the usual command-line syntax described in that section.


<tt>[[XmlTools/Full_documentation#.40CUSTOM_CODE|@CUSTOM_CODE]]</tt>
<tt>[[XmlTools/Full_documentation#.40CUSTOM_CODE|@CUSTOM_CODE]]</tt>
:Executes the [[wikipedia:JavaScript|JavaScript]] code for XML editing. When specifically you are using this operation for [[Anniversary_Edition/Framework#XML_patching|AE Patches]] <u>you should try to avoid this operation as much as possible</u> because it is much slower than the native XmlTools commands;
:Executes the following [[wikipedia:JavaScript|JavaScript]] code for the purpose of editing the XML. If you are creating a [[Anniversary_Edition/Framework#XML_patching|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.
 
===Input Options===


The values of the following options inputs must be <u>always</u> inside of quotes (""). The input options use [http://c2.com/cgi/wiki?PascalCase pascal casing].
===Command options===
The values supplied for the following options must <u>always</u> be inside quotes (""). The option names use [http://c2.com/cgi/wiki?PascalCase Pascal case].


<tt>Files</tt>
<tt>Files</tt>
:[http://www.computerhope.com/jargon/w/wildcard.htm Wildcard] that matches the file(s) that you want to edit;
:[http://www.computerhope.com/jargon/w/wildcard.htm Wildcard] that matches the file(s) that you want to edit


<tt>ElementName</tt>
<tt>ElementName</tt>
:XML element name where processing will occur;
:XML element name where processing will occur


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


<tt>AttributeName</tt>
<tt>AttributeName</tt>
:XML attribute name of the ElementName, used as filter;
:XML attribute name of the ElementName (used as filter)


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


<tt>XPathExpression</tt>
<tt>XPathExpression</tt>
:[http://zvon.org/comp/r/tut-XPath_1.html#intro XPath 1.0] expression to select elements where the processing will occur;
:[http://zvon.org/comp/r/tut-XPath_1.html#intro XPath 1.0] expression (used as filter)


<tt>Options</tt>
<tt>Options</tt>
:Allows to specify any option of [[#Command-line_operations| command-line operations]]. Values must be within " ' " to avoid confusion with the quotes.
: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:Modding tutorials]]
[[Category:Bi-platform modding tools]][[Category:Completed modding tools]][[Category:Modding tutorials]]