![]() |
| Previous Top Next |
XMLValidator |
Description
The XMLValidator interface provides methods to test:
| • | The well-formedness of an XML document. |
| • | The validity of an XML document against a DTD or XML Schema referenced from within the XML document. |
| • | The validity of an XML document against a DTD or XML Schema supplied externally via the code. |
All these methods return Boolean TRUE or FALSE. See examples below.
Note: Where string inputs are to be interpreted as URLs, absolute paths should be used. If a relative path is used, a mechanism to resolve the relative path should be defined in the calling module.
Methods
The following methods are available:
IsWellFormed
IsWellFormed checks the well-formedness of the XML document. Returns TRUE if the XML document is well-formed, FALSE if it is not well-formed.
IsValid
IsValid validates the XML document against the DTD or XML Schema referenced in the XML document. Returns TRUE if the XML document is valid, FALSE if invalid. To validate against a DTD or XML Schema not referenced in the XML document, use the method IsValidWithExternalSchemaOrDTD.
IsValidWithExternalSchemaOrDTD
IsValidWithExternalSchemaOrDTD validates the XML document against the DTD or XML Schema supplied by any one of the following properties: SchemaFileName, DTDFileName, SchemaFromText, or DTDFromText. If more than one of these properties has values set for it, then the IsValidWithExternalSchemaOrDTD method uses the property that has been set last. Returns TRUE if the XML document is valid, FALSE if invalid. To validate against a DTD or XML Schema referenced in the XML document, use the method IsValid.
Note: Validation and well-formedness checks must always occur after assigning the XML and/or DTD or XML Schema document to the respective properties.
Properties
The following properties are defined:
InputXMLFileName
A string input that is read as a URL to locate the XML file to be validated.
SchemaFileName
A string input that is read as a URL to locate the XML Schema file against which the XML document is to be validated.
DTDFileName
A string input that is read as a URL to locate the DTD file against which the XML document is to be validated.
InputXMLFromText
A string input that constructs an XML document.
SchemaFromText
A string input that constructs an XML Schema document.
DTDFromText
A string input that constructs a DTD document.
LastErrorMessage
Returns the last error message.
Examples
Given below is a single Visual Basic procedure that shows how the methods and properties of the XMLValidator interface can be used. This code is intended for use as a macro in an MS Excel worksheet, and references to worksheet cells indicate locations of input or output data. The file c:\AltovaXML\test.xml is assumed to contain a reference to a DTD.
Sub CommandButton1_Click()
Set objAltovaXML = CreateObject("AltovaXML.Application")
objAltovaXML.XMLValidator.InputXMLFromText = "<?xml version='1.0' encoding='UTF-8'?><a><b/></a>"
Sheet1.Cells(4, 2) = objAltovaXML.XMLValidator.IsWellFormed
objAltovaXML.XMLValidator.InputXMLFileName = "c:\AltovaXML\test.xml"
Sheet1.Cells(5, 2) = objAltovaXML.XMLValidator.IsValid
objAltovaXML.XMLValidator.InputXMLFileName = "c:\AltovaXML\test.xml"
objAltovaXML.XMLValidator.DTDFileName = "c:\AltovaXML\test.dtd"
Sheet1.Cells(6, 2) = objAltovaXML.XMLValidator.IsValidWithExternalSchemaOrDTD
objAltovaXML.XMLValidator.InputXMLFromText = "<?xml version='1.0' encoding='UTF-8'?><a><b/></a>"
objAltovaXML.XMLValidator.DTDFileName = "c:\AltovaXML\test.dtd"
Sheet1.Cells(7, 2) = objAltovaXML.XMLValidator.IsValidWithExternalSchemaOrDTD
End Sub
|