Main Content

matlab.io.xml.dom.ParseErrorHandler Class

Namespace: matlab.io.xml.dom

Abstract base class for parse error handlers

Since R2021b

Description

matlab.io.xml.dom.ParseErrorHandler is an abstract base class for deriving error handlers that handle XML markup errors encountered by a parser when parsing an XML file or string. You must implement the handleError method in classes derived from this abstract base class.

You cannot instantiate an object of this abstract class.

The matlab.io.xml.dom.ParseErrorHandler class is a handle class.

Class Attributes

Abstract
true
Sealed
false
ConstructOnLoad
true

For information on class attributes, see Class Attributes.

Methods

expand all

Examples

collapse all

This example shows how to create an error handler by using the abstract class matlab.io.xml.dom.ParseErrorHandler.

Create Derived Class

Define a class that derives from the abstract class matlab.io.xml.dom.ParseErrorHandler.

type MyParseErrorHandler
classdef MyParseErrorHandler < matlab.io.xml.dom.ParseErrorHandler

    properties
        Errors  % Object to store error list
    end
    methods
        function cont = handleError(obj,error)
            
            import matlab.io.xml.dom.*
            
            % Create index for individual errors 
            idx = numel(obj.Errors) + 1;
            
            severity = getSeverity(error);
            
            % Assign severity and messages of the errors
            obj.Errors(idx).Severity = severity;
            obj.Errors(idx).Message = error.Message;
            
            % Find location of the error
            loc = getLocation(error);

            obj.Errors(idx).Location.FilePath = loc.FilePath;
            obj.Errors(idx).Location.LineNo = loc.LineNumber;
            obj.Errors(idx).Location.ColNo = loc.ColumnNumber;

            % Set the condition for the method output and to halt parsing
            if severity == "fatalError"
                cont = false; % Halt parsing
            else
                cont = true; % Continue parsing
            end
        end
    end
end

Use Derived Handler

To use the derived handler from this class, assign the handler to the ErrorHandler property of a parsers Configuration property.

p = matlab.io.xml.dom.Parser;
h = MyParseErrorHandler;
p.Configuration.ErrorHandler = h;

Version History

Introduced in R2021b