Jump to content

XmlTools: Difference between revisions

3,216 bytes added ,  28 May 2013
words more gooder; adding syntax section a la OniSplit
m (XmlTools now require .NET 3.5)
(words more gooder; adding syntax section a la OniSplit)
Line 1: Line 1:
{{finish}}
==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]].


It can be used as a standalone tool or as a base for another tools.
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 package [http://mods.oni2.net/node/224 here] (actual program folder found inside the plain/xxx_only/Tools/ folder).
*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 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 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).
*'''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''' (for example, invert an OBAN animation).
*'''Invert a chain of values''' (sample use: inverting an OBAN animation).
*'''Add new values to XML elements''' (for example, add the 'unkillable' flag to some characters in a level).
*'''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''' (for example, remove boss shields from characters in a level).
*'''Remove values from XML elements''' (sample use: removing 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 XML elements''' (sample use: increasing the health of characters by replacing the old HP value).
*'''Add custom XML to existing files (patch only).'''
*'''Add/remove XML elements''' (sample use: adding particles to an attack).
*'''Remove XML from existing files (patch only).'''
*'''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 javascript (patch only).'''
*'''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.


==Using it==
==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 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.
The basic syntax is:
:::On the Mac, be sure to use / rather than \ in paths. The following instructions are for Windows by default.
{|
|-
|'''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 arguments===
==Global command-line arguments==
You may use these arguments with each command listed in the next section:
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>-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'''
!
! 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>-element:<XML tag></tt>||Specifies XML tag to look for in the file||'''Required'''
|'''(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 avoid override elements that have the same name but have different parent elements ||'''Optional'''
|'''(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
|}
|}
e.g.:


<pre>
;-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>
</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.
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>-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.||'''Optional'''
|}


===Command-line operations===
<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 XML chain, starting at the -newvalue;
: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 XML chain
: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 file operations==
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.
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 [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 when is possible edit your code using other XmlTools commands.
: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 javascript code is called ''W3C DOM Parser'' and its documentation is available [http://xmljs.sourceforge.net/website/documentation-w3cdom.html here].
: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.
: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:
: Usage example:
Sample XML file to be patched:
 
 
XML code:
  <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 bellow javascript code will change the FirstLevel tag value from 4 to 0 --></span>
       <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:




Javascript code:
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">// Change level from 4 to 0</span>
       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 [File<quoted file name>] argument the operation will applied over all the XML files in the same directory of xmlTools.exe.
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 ('*', '?').
 
Also this [File<quoted file name>] allows wildcards ('*','?').


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