直接アクセスするには、現在のドキュメントを検証するボタンが必要です。 メソッドは前のセクションで使用されたメソッドに類似しています。
最初はボタンを与えます:
<input type="button" value="Validate" onclick="BtnValidate()">
現在のドキュメントを検証するスクリプトを与えます。
<SCRIPT ID=Javahandlers LANGUAGE=javascript>
// ----------------------------------------------------------------------
// 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("Docuent is valid"); }
}
</SCRIPT>