Add Buttons for Code Generation

www.altova.com Print this Topic Previous Page Up One Level Next page

Home >  Programmers' Reference > ActiveX Integration > ActiveX Integration Examples > HTML > HTML Integration at Application Level >

Add Buttons for Code Generation

For direct access, we want to have a button that will validate the current document. The method is similar to that used in the previous section.

 

First comes the button:

 

<input type="button" value="Validate" onclick="BtnValidate()">

 

Then we provide the script that will validate the current document.

 

// ----------------------------------------------------------------------
// check validity of current document.
// if validation fails, show validation result in alert box .
function BtnValidate()
{
  // get top-level object of automation interface
  var objApp = objXMLSpyControl.Application;
 
  // get the active document
  var objDocument = objApp.ActiveDocument;
 
  if ( objDocument == null )
     alert( "no active document found" );
  else
  {
    // define as arrays to support their usage as return parameters
    var errorText = new Array(1);
    var errorPos = new Array(1);
    var badData = new Array(1);
 
    var valid = objDocument.IsValid(errorText, errorPos, badData);
 
    if (! valid)
     {
          // compose the error description
          var text = errorText;
 
          // access that XMLData object only if filled in
          if (badData[0] != null)
              text += "(" + badData[0].Name + "/" + badData[0].TextValue + ")";
 
 
           alert("Validation error[" + errorPos + "]: " + text);
     }
    else
        alert("Document is valid");
  }
}


© 2019 Altova GmbH