In the example, we add some more buttons to show some automation code.
<!-- add some buttons associated with above editor. --> <!-- generation of code is now implemented using the XMLSpy automation --> <!-- interface to select a target folder without prompting the user. --> <p> <input type="button" value="New File" onclick="BtnNewFile(objDoc1)"> <input type="button" value="Save File" onclick="BtnSaveFile(objDoc1)"> <input type="text" title="Path" id="strPath" width="150"> <input type="button" value="Open OrgChart.pxf" onclick="BtnOpenFile(objDoc1, 'OrgChart.pxf')"> </p> |
The corresponding JavaScript looks like this:
// ------------------------------------------------------------------- // open a new empty document in the specified document control window. function BtnNewFile(objDocCtrl) { objDocCtrl.Open(""); objDocCtrl.setActive(); } // ------------------------------------------------------------------- // Saves the current file in the specified document control window. function BtnSaveFile(objDocCtrl) { if(objDocCtrl.Path.length > 0) objDocCtrl.Save(); else { if(strPath.value.length > 0) { objDocCtrl.Path = strPath.value; objDocCtrl.Save(); } else { alert("Please set path for the document first!"); strPath.focus(); } } objDocCtrl.setActive(); } // --------------------------------------------------------- // open a document in the specified document control window. function BtnOpenFile(objDocCtrl, strFileName) { // do not use XMLSpyX.Application.OpenDocument(...) to open a document, // since then XMLSpyControl wouldn't know a control window to show // the document in. Instead: var strPath = MakeAbsolutePath(strFileName); DoOpenFile(objDocCtrl, strPath); } |