Jump to content

XmlTools: Difference between revisions

1,973 bytes added ,  19 May 2013
adding new feature: custom javascript code for editing XML
(some fixes)
(adding new feature: custom javascript code for editing XML)
Line 111: Line 111:
: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.:
: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.:
  @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>
: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.
: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:
XML code:
<Oni>
  <Animation>
    <Lookup>
      <Type>KickForward</Type>
      <AimingType>KickForward</AimingType>
      <FromState>RunBackStart</FromState>
      <ToState>Standing</ToState>
      <Varient>Combat</Varient>
      <FirstLevel>4</FirstLevel> <span style="color:#008000"><!-- The bellow javascript code will change the FirstLevel tag value from 4 to 0 --></span>
      ...
      </Lookup>
  </Animation>
</Oni>
Javascript code:
@CUSTOMCODE
<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.
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.
489

edits