XmlTools: Difference between revisions
Script 10k (talk | contribs) m (XmlTools now require .NET 3.5) |
(words more gooder; adding syntax section a la OniSplit) |
||
Line 1: | Line 1: | ||
==Overview== | ==Overview== | ||
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 (Latest Mono required) and Windows (.NET 3.5 required). | 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 (Latest Mono required) and Windows (.NET 3.5 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]]. | 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]] so that resources could be patched smartly. To learn about the overall process, read [[Making a patch mod]] and [[Anniversary Edition/Framework#XML patching]]. | ||
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. | |||
==Links== | ==Links== | ||
*Download the tool | *Download the tool in a standalone form [http://mods.oni2.net/node/224 here] or download it using the AEI's [[AEI#Tools|Tool Manager]]. | ||
*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 tool [[Vago_(tool)|Vago]]. | ||
==Features== | ==Features== | ||
*'''Modify a chain of values''' ( | *'''Modify a chain of values''' by supplying a new starting point for the chain (sample use: repositioning an OBAN animation or adjusting the pelvis height of a TRAM). | ||
*'''Invert a chain of values''' ( | *'''Invert a chain of values''' (sample use: inverting an OBAN animation). | ||
*'''Add new values | *'''Add new values into XML elements''' (sample use: adding an item to a space-separated list, i.e. adding to some characters in a level). | ||
*'''Remove values from XML elements''' ( | *'''Remove values from XML elements''' (sample use: removing boss shields from characters in a level). | ||
*'''Replace values in XML elements''' ( | *'''Replace values in XML elements''' (sample use: increasing the health of characters by replacing the old HP value). | ||
*'''Add | *'''Add/remove XML elements''' (sample use: adding particles to an attack). | ||
*'''Powerful custom XML editing using JavaScript''' (sample use: any time you need to insert XML dynamically based on what you find in the XML file, or employ logical or mathematical operations). | |||
*'''Powerful custom XML editing using | |||
*'''Patch file support''' allows the modder to list multiple commands in a file, on separate lines, to all be performed at once. | *'''Patch file support''' allows the modder to list multiple commands in a file, on separate lines, to all be performed at once. | ||
== | ==Syntax== | ||
The following actions are listed when calling XmlTools with no options passed in. You can get the version with the argument "version". | 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 <tt>/</tt> rather than <tt>\</tt> in paths. The following instructions are for Windows by default. | ||
The basic syntax is: | |||
{| | |||
|- | |||
|'''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;">addvalue</span> <span style="background:rgb(255,156,156); border-radius:0.33em;">-value:"DropWeapon"</span> <span style="background:rgb(156,255,156); border-radius:0.33em;">-element:Flags</span> <span style="background:rgb(156,255,156); border-radius:0.33em;">-filename:TRAMSTRCOMhit_fallen1.xml</span></tt> | |||
|- | |||
|'''Mac'''||<tt><span style="background:rgb(235,235,235); border-radius:0.33em;">mono xmlTools.exe</span> <span style="background:rgb(175,175,255); border-radius:0.33em;">addvalue</span> <span style="background:rgb(255,156,156); border-radius:0.33em;">-value:"DropWeapon"</span> <span style="background:rgb(156,255,156); border-radius:0.33em;">-element:Flags</span> <span style="background:rgb(156,255,156); border-radius:0.33em;">-filename:TRAMSTRCOMhit_fallen1.xml</span></tt> | |||
|} | |||
Here's how it breaks down: | |||
{| | |||
! style="width:130px"| | |||
|- valign="top" | |||
|<span style="background:rgb(235,235,235); border-radius:0.33em;">'''Invocation'''</span> | |||
|Windows can refer to the program directly, but Macs use Mono to run the .NET app; note also that if xmlTools.exe is not in the Command Prompt/Terminal's current directory, you must provide the full path to it or set the path variable. | |||
|- | |||
|<span style="background:rgb(175,175,255); border-radius:0.33em;">'''Operation'''</span>||The command to perform. Note that commands are <u>not</u> prefaced by a <tt>-</tt>, whereas the arguments supplied after the commands <u>are</u>. | |||
|- valign="top" | |||
|<span style="background:rgb(255,156,156); border-radius:0.33em;">'''Operation-specific argument(s)'''</span>||This is where you supply the arguments that this specific command needs. As seen below, addvalue requires the value to add to a space-separated list, so we provide that here. Note the use of quotes as specified in the command's documentation below. | |||
|- | |||
|<span style="background:rgb(156,255,156); border-radius:0.33em;">'''Global argument(s)'''</span>||Make sure you specify the full path to the file if the file is not in the current directory. No quotes are used for these commands unless you need to pass a file name path with spaces in it. | |||
|} | |||
==Global command-line arguments== | |||
You may use these arguments with each command listed in the | You may use these arguments with each command listed in the "Command-line operations" section below. Note that the <tt>-element</tt> is required in all CLI commands, otherwise you can't tell XmlTools what to modify. | ||
{| | {| | ||
|<tt>- | ! | ||
! style="width:175px"| | |||
|- | |||
|'''(Optional)'''||<tt>-nobackups</tt>||XmlTools will not create a backup file (speeds up operations) | |||
|- | |||
|'''(Optional)'''||<tt>-debug</tt>||Not used yet. It will be probably used to output some debugging information in the future. | |||
|- | |- | ||
|<tt>- | |'''(Optional)'''||<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) | ||
|- | |||
|style="background-color:rgb(175,175,0)"|'''(Required)'''||<tt>-element:<XML tag></tt>||Specifies XML tag to look for in the file | |||
|- | |- | ||
|<tt>-parelement:<XML tag></tt>||Specifies XML tag that contains -element tag to | |'''(Optional)'''||<tt>-parelement:<XML tag></tt>||Specifies XML tag that contains -element tag to pick between elements that have the same name but have different parent elements | ||
|} | |} | ||
;-parelement | |||
<xml> | :Let's say that an XML file has two tags with the same name, e.g.: | ||
<xml> | |||
<Volume> | <Volume> | ||
<Min>1</Min> | <Min>1</Min> | ||
Line 51: | Line 73: | ||
<Max>1</Max> | <Max>1</Max> | ||
</Pitch> | </Pitch> | ||
<xml | <xml> | ||
In the above code you can differentiate the "Min" elements by | In the above code you can differentiate the two "Min" elements by their parent elements. So you can use <tt>-element:Min -parelement:Pitch</tt> to refer to the "Min" element under "Pitch". | ||
==Command-line operations== | |||
Arguments in square brackets are optional. | |||
<tt>updatechainvalues -newvalue:<quoted string> [-valpositions:<quoted string>] [-valrelation:<quoted string>]</tt> | <tt>updatechainvalues -newvalue:<quoted string> [-valpositions:<quoted string>] [-valrelation:<quoted string>]</tt> | ||
:Update a | :Update a value 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>; | :<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>; | ||
:<tt>-valrelation</tt> (optional) means ??? | :<tt>-valrelation</tt> (optional) means ??? | ||
<tt>invert</tt> | <tt>invert</tt> | ||
:Inverts a | :Inverts a value chain | ||
<tt>addvalue -value:<quoted string></tt> | <tt>addvalue -value:<quoted string></tt> | ||
Line 91: | Line 107: | ||
:or to named files with <tt>-forceinfiles</tt> argument (allows wildcards '*','?'); see below for patch commands | :or to named files with <tt>-forceinfiles</tt> argument (allows wildcards '*','?'); see below for patch commands | ||
==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, 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. | |||
Arguments in square brackets are optional. | |||
<tt>@ADDTO Element <quoted tag name> [ParentElement <quoted tag name>] [File<quoted file name>]</tt> | <tt>@ADDTO Element <quoted tag name> [ParentElement <quoted tag name>] [File<quoted file name>]</tt> | ||
Line 106: | Line 126: | ||
</xml> | </xml> | ||
<tt>@REMOVE Element <quoted tag name> [ParentElement <quoted tag name>] [File<quoted file name>]</tt> | <tt>@REMOVE Element <quoted tag name> [ParentElement <quoted tag name>] [File <quoted file name>]</tt> | ||
:Removes named element from the array tag named by ParentElement | :Removes named element from the array tag named by ParentElement | ||
Line 113: | Line 133: | ||
@COMMAND invert -element:Height -parelement:Heights -filename:test.xml | @COMMAND invert -element:Height -parelement:Heights -filename:test.xml | ||
<tt>@CUSTOMCODE [File<quoted file name>]</tt> | <tt>@CUSTOMCODE [File <quoted file name>]</tt> | ||
:Executes the | :Executes the JavaScript code inside a <tt><nowiki><code></nowiki></tt> tag. <u>You should avoid this method when possible</u> because it is much slower than the native XmlTools commands. | ||
:The XML library that you can use in | :The XML library that you can use in your JavaScript code is called ''W3C DOM Parser'' and its documentation is available [http://xmljs.sourceforge.net/website/documentation-w3cdom.html here]. The most important thing to know about the DOM Parser is that the contents of the XML file are saved in 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: | |||
: Usage example: | Sample XML file to be patched: | ||
XML | |||
<Oni> | <Oni> | ||
<Animation> | <Animation> | ||
Line 129: | Line 146: | ||
<ToState>Standing</ToState> | <ToState>Standing</ToState> | ||
<Varient>Combat</Varient> | <Varient>Combat</Varient> | ||
<FirstLevel>4</FirstLevel> <span style="color:#008000"><nowiki><!--</nowiki> The | <FirstLevel>4</FirstLevel><span style="color:#008000"><nowiki><!--</nowiki>The JavaScript code below will change this tag's value from 4 to 0--></span> | ||
... | ... | ||
</Lookup> | </Lookup> | ||
Line 136: | Line 153: | ||
XmlTools patch file contents: | |||
@CUSTOMCODE | @CUSTOMCODE | ||
<nowiki><code></nowiki> | <nowiki><code></nowiki> | ||
var parser = new DOMImplementation(); <span style="color:#008000">// instantiate the W3C DOM Parser</span> | 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 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; | var levelNode = domDoc.getDocumentElement().getElementsByTagName("FirstLevel").item(0).firstChild; | ||
if(levelNode.toString() == "4") | if (levelNode.toString() == "4") | ||
levelNode.setNodeValue("0"); <span style="color:#008000">// | 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> | |||
$xmlData=domDoc.getDocumentElement().getXML(); <span style="color:#008000">// update the global variable with the new XML</span> | |||
<nowiki></code></nowiki> | <nowiki></code></nowiki> | ||
Note that if you don't specify the optional | Note that if you don't specify the optional <tt>File <quoted file name></tt> argument, the operation will applied over all the XML files in the same directory as xmlTools.exe. The File argument allows wildcards ('*', '?'). | ||
[[Category:Bi-platform modding tools]][[Category:Completed modding tools]] | [[Category:Bi-platform modding tools]][[Category:Completed modding tools]] |
Revision as of 18:23, 28 May 2013
Overview
XmlTools is a command-line modding tool that operates on XML files, especially those exported by OniSplit. It was developed in C# and works in both Mac OS X (Latest Mono required) and Windows (.NET 3.5 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 so that resources could be patched smartly. To learn about the overall process, read Making a patch mod and Anniversary Edition/Framework#XML patching.
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.
Links
- Download the tool in a standalone form here or download it using the AEI's Tool Manager.
- XmlTools is used along with OniSplit as the backend for the GUI tool Vago.
Features
- Modify a chain of values by supplying a new starting point for the chain (sample use: repositioning an OBAN animation or adjusting the pelvis height of a TRAM).
- Invert a chain of values (sample use: inverting an OBAN animation).
- Add new values into XML elements (sample use: adding an item to a space-separated list, i.e. adding to some characters in a level).
- Remove values from XML elements (sample use: removing boss shields from characters in a level).
- Replace values in XML elements (sample use: increasing the health of characters by replacing the old HP value).
- Add/remove XML elements (sample use: adding particles to an attack).
- Powerful custom XML editing using JavaScript (sample use: any time you need to insert XML dynamically based on what you find in the XML file, or employ logical or mathematical operations).
- Patch file support allows the modder to list multiple commands in a file, on separate lines, to all be performed at once.
Syntax
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 xmlTools.exe (Windows) or mono xmlTools.exe (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.
The basic syntax is:
Windows | xmlTools.exe addvalue -value:"DropWeapon" -element:Flags -filename:TRAMSTRCOMhit_fallen1.xml |
Mac | mono xmlTools.exe addvalue -value:"DropWeapon" -element:Flags -filename:TRAMSTRCOMhit_fallen1.xml |
Here's how it breaks down:
Invocation | Windows can refer to the program directly, but Macs use Mono to run the .NET app; note also that if xmlTools.exe is not in the Command Prompt/Terminal's current directory, you must provide the full path to it or set the path variable. |
Operation | The command to perform. Note that commands are not prefaced by a -, whereas the arguments supplied after the commands are. |
Operation-specific argument(s) | This is where you supply the arguments that this specific command needs. As seen below, addvalue requires the value to add to a space-separated list, so we provide that here. Note the use of quotes as specified in the command's documentation below. |
Global argument(s) | Make sure you specify the full path to the file if the file is not in the current directory. No quotes are used for these commands unless you need to pass a file name path with spaces in it. |
Global command-line arguments
You may use these arguments with each command listed in the "Command-line operations" section below. Note that the -element is required in all CLI commands, otherwise you can't tell XmlTools what to modify.
(Optional) | -nobackups | XmlTools will not create a backup file (speeds up operations) |
(Optional) | -debug | Not used yet. It will be probably used to output some debugging information in the future. |
(Optional) | -filename:<XML file> | 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) |
(Required) | -element:<XML tag> | Specifies XML tag to look for in the file |
(Optional) | -parelement:<XML tag> | Specifies XML tag that contains -element tag to pick between elements that have the same name but have different parent elements |
- -parelement
- Let's say that an XML file has two tags with the same name, e.g.:
<xml> <Volume> <Min>1</Min> <Max>1</Max> </Volume> <Pitch> <Min>1</Min> <Max>1</Max> </Pitch> <xml>
In the above code you can differentiate the two "Min" elements by their parent elements. So you can use -element:Min -parelement:Pitch to refer to the "Min" element under "Pitch".
Command-line operations
Arguments in square brackets are optional.
updatechainvalues -newvalue:<quoted string> [-valpositions:<quoted string>] [-valrelation:<quoted string>]
- Update a value chain, starting at the -newvalue;
- -valpositions (optional) is zero-indexed and can be a single value or a space-separated list, e.g. -valpositions=0 1 4;
- -valrelation (optional) means ???
invert
- Inverts a value chain
addvalue -value:<quoted string>
- Adds value or space-separated list of values into an element
removevalue -value:<quoted string>
- Removes value or space-separated list of values from an element
replacevalue -oldvalue:<string> -newvalue:<string>
- Replaces specified old value, if found, with new value
replaceall -value:<string> [-valpositions:<quoted string>]
- Replaces value in element with new value, no matter its previous value
showerrtypes
- Show errors numbers and they internal name
patchfile [-forceinfiles:<file names>]
- Changes -filename argument to refer to a patch file and applies this patch to the specified files using the [File<quoted file name>] argument,
- or to named files with -forceinfiles argument (allows wildcards '*','?'); see below for patch commands
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, 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.
Arguments in square brackets are optional.
@ADDTO Element <quoted tag name> [ParentElement <quoted tag name>] [File<quoted file name>]
- Adds the raw XML that follows to the named array tag, e.g.:
@ADDTO Element "Particles" <xml> <Particle> <Start>0</Start> <End>45</End> <Bone>Head</Bone> <Name>glass_break</Name> </Particle> </xml>
@REMOVE Element <quoted tag name> [ParentElement <quoted tag name>] [File <quoted file name>]
- Removes named element from the array tag named by ParentElement
@COMMAND <command-line string>
- Runs any of the commands available under "Command-line operations" above. Use standard command-line syntax described in that section, including -filename, e.g.:
@COMMAND invert -element:Height -parelement:Heights -filename:test.xml
@CUSTOMCODE [File <quoted file name>]
- Executes the JavaScript code inside a <code> tag. You should avoid this method when possible because it is much slower than the native XmlTools commands.
- The XML library that you can use in your JavaScript code is called W3C DOM Parser and its documentation is available here. The most important thing to know about the DOM Parser is that the contents of the XML file are saved in 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:
Sample XML file to be patched:
<Oni>
<Animation>
<Lookup>
<Type>KickForward</Type>
<AimingType>KickForward</AimingType>
<FromState>RunBackStart</FromState>
<ToState>Standing</ToState>
<Varient>Combat</Varient>
<FirstLevel>4</FirstLevel><!--The JavaScript code below will change this tag's value from 4 to 0-->
...
</Lookup>
</Animation>
</Oni>
XmlTools patch file contents:
@CUSTOMCODE <code> var parser = new DOMImplementation(); // instantiate the W3C DOM Parser var domDoc = parser.loadXML($xmlData); // load the XML into the parser and get the DOMDocument, using $xmlData variable var levelNode = domDoc.getDocumentElement().getElementsByTagName("FirstLevel").item(0).firstChild; if (levelNode.toString() == "4") levelNode.setNodeValue("0"); // change level from 4 to 0 $xmlData = domDoc.getDocumentElement().getXML(); // update the global variable with the new XML </code>
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 as xmlTools.exe. The File argument allows wildcards ('*', '?').