Altova Authentic 2025 Desktop

Method: HRESULT IsValid([in, out] VARIANT *strError, [in, out] VARIANT *nErrorPos, [in, out] VARIANT *pBadData, [out,retval] VARIANT_BOOL *bValid);

 

 

Return Value

True if the document is valid, false if not. To call IsValid(), the application GUI must be visible. (If you wish to validate without the GUI being visible, please use Altova RaptorXML Server.)

 

Description

IsValid validates the document against its associated schema or DTD. strError gives you the same error message as when you validate the file within the GUI.

 

 

Errors

1400

The object is no longer valid.

1407

Invalid parameter or invalid address for the return parameter was specified.

1408

Unable to validate file.

 

 

Example

The following C++ code snippet provides an example of how to use the IsValid method.

 

#import "XMLSpy.tlb"

 

 

CComPtr< XMLSpyLib::IDocument12> ipDoc = ipXMLSpy->GetActiveDocument();

if ( ipDoc )

{

      // prepare in/out parameters for IsValid call

      CComVariant variantError;

      CComVariant variantErrorPos;

      CComVariant variantBadData;

      // IsValid always shows a dialog with the validation result. This cannot be turned off.

      bool bIsValid = ipDoc->IsValid( &variantError, &variantErrorPos, &variantBadData ) == VARIANT_TRUE;

 

      if ( !bIsValid )

       {

              // retrieve values from out parameters

              CString strError = (V_VT( &variantError ) == VT_BSTR ? V_BSTR( &variantError ) : _T( "" ));

              long npos = (V_VT( &variantErrorPos ) == VT_I4 ? V_I4( &variantErrorPos ) : -1);

              CComQIPtr< XMLSpyLib::IXMLData > ipXMLBadData = (V_VT( &variantBadData ) == VT_DISPATCH ? V_DISPATCH( &variantBadData ) : nullptr);

 

              if ( ipXMLBadData )

                      strError += CString( _T("\n\n Node: ") ) + (LPCWSTR)ipXMLBadData->GetName();

 

              if ( !strError.IsEmpty() )

                      AfxMessageBox( "Validation failed - " + strError );

       }

}

 

© 2018-2024 Altova GmbH