Jump to content

XmlTools/Full documentation: Difference between revisions

m
link fix
m (→‎Description: forgot bold tags)
m (link fix)
 
(3 intermediate revisions by 2 users not shown)
Line 555: Line 555:


'''XmlTools patch command:'''
'''XmlTools patch command:'''
  @REMOVE_NODES XPathExpression "/Oni/ONCP/Particles/ONCPParticle[Name = 'glass_break']" Files "ONCCgriffin_swat.xml"
  @REMOVE_NODES XPathExpression "/Oni/ONCP/Particles/ONCPParticle[@Name = 'glass_break']" Files "ONCCgriffin_swat.xml"


{| style="margin: 1em auto 1em auto;" <!-- Centers table -->
{| style="margin: 1em auto 1em auto;" <!-- Centers table -->
Line 619: Line 619:
===@CUSTOM_CODE===
===@CUSTOM_CODE===
====Description====
====Description====
This operation allows you to use [[wikipedia:JavaScript|JavaScript]] to edit XML. You can use this for complex logic and mathematical tasks which aren't supported by XmlTools' basic operations. <u>You should only use this option as a '''last resort'''</u> if you are using it for a [[Anniversary_Edition/Framework#XML_patching|patch mod]], because it is '''MUCH slower''' than all the other native options. Try to <u>optimize your code as much as possible</u>, as the complexity of the code has a large effect on the overall speed of XmlTools in running JavaScript.
This operation allows you to use [[wikipedia:JavaScript|JavaScript]] to edit XML. You can use this for complex logic and mathematical tasks which aren't supported by XmlTools' basic operations. <u>You should only use this option as a '''last resort'''</u> if you are using it for a [[Making a patch mod|patch mod]], because it is '''MUCH slower''' than all the other native options. Try to <u>optimize your code as much as possible</u>, as the complexity of the code has a large effect on the overall speed of XmlTools in running JavaScript.


Usage:
Usage:
Line 635: Line 635:
The <tt>$xmlData</tt> global variable contains the contents of the XML file on disk. After you modify the XML, update this variable again with the new XML in order for XmlTools to update the file on disk, otherwise your changes will not take effect.
The <tt>$xmlData</tt> global variable contains the contents of the XML file on disk. After you modify the XML, update this variable again with the new XML in order for XmlTools to update the file on disk, otherwise your changes will not take effect.


XmlTools uses the [http://www.petetracey.com/jsxml/index.html JSXML XML Tools] JavaScript libraries to allow you to operate upon the XML. You can read its documentation on its [http://www.petetracey.com/jsxml/documentation.html website] or [http://script10k.oni2.net/documentation/xmltools/jsxml-documentation.htm here].
XmlTools uses the JSXML XML Tools (<nowiki>http://www.petetracey.com/jsxml/index.html</nowiki>, dead link) JavaScript libraries to allow you to operate upon the XML. You can read its documentation on its website (<nowiki>http://www.petetracey.com/jsxml/documentation.html</nowiki>, dead link) or [http://script10k.oni2.net/documentation/xmltools/jsxml-documentation.htm here].


====Example====
====Example====
Let's say you want to add one additional ammo clip and energy cell to all characters that are on the TCTF team.
Let's say you want to double the ammo clips and energy cells to all characters that are on the TCTF team.


'''XmlTools patch command:'''
'''XmlTools patch command:'''
Line 664: Line 664:
                     currCellsElement=currChar.childElement("OSD").childElement("Inventory").childElement("EnergyCell").childElement("Use");
                     currCellsElement=currChar.childElement("OSD").childElement("Inventory").childElement("EnergyCell").childElement("Use");
                      
                      
                     <span style="color:green">// Add 1 to the current amount of ammo and cells to use</span>
                     <span style="color:green">// Double the current amount of ammo and cells that the character can use</span>
                     currAmmoElement.text=parseInt(currAmmoElement.text)+1;
                     currAmmoElement.text=parseInt(currAmmoElement.text)*2;
                     currCellsElement.text=parseInt(currCellsElement.text)+1;
                     currCellsElement.text=parseInt(currCellsElement.text)*2;
               }
               }
       }
       }
Line 689: Line 689:
                         <Inventory>
                         <Inventory>
                               <Ammo>
                               <Ammo>
                                     <Use><span style="color:blue">'''0'''</span></Use>
                                     <Use><span style="color:blue">'''2'''</span></Use>
                                     ...
                                     ...
                               </Ammo>
                               </Ammo>
Line 733: Line 733:
                               </Ammo>
                               </Ammo>
                               <EnergyCell>
                               <EnergyCell>
                                     <Use>'''0'''</Use>
                                     <Use>'''2'''</Use>
                                     ...
                                     ...
                               </EnergyCell>
                               </EnergyCell>
Line 757: Line 757:
                         <Inventory>
                         <Inventory>
                               <Ammo>
                               <Ammo>
                                     <Use><span style="color:red">'''1'''</span></Use>
                                     <Use><span style="color:red">'''4'''</span></Use>
                                     ...
                                     ...
                               </Ammo>
                               </Ammo>
                               <EnergyCell>
                               <EnergyCell>
                                     <Use><span style="color:red">'''1'''</span></Use>
                                     <Use><span style="color:red">'''0'''</span></Use>
                                     ...
                                     ...
                               </EnergyCell>
                               </EnergyCell>
Line 777: Line 777:
                         <Inventory>
                         <Inventory>
                               <Ammo>
                               <Ammo>
                                     <Use><span style="color:red">'''4'''</span></Use>
                                     <Use><span style="color:red">'''6'''</span></Use>
                                     ...
                                     ...
                               </Ammo>
                               </Ammo>
Line 801: Line 801:
                               </Ammo>
                               </Ammo>
                               <EnergyCell>
                               <EnergyCell>
                                     <Use>'''0'''</Use>
                                     <Use>'''2'''</Use>
                                     ...
                                     ...
                               </EnergyCell>
                               </EnergyCell>