Main Content

matlab.io.xml.dom.ResourceIdentifier Class

Namespace: matlab.io.xml.dom

XML resource identifier

Since R2021a

Description

An object of the matlab.io.xml.dom.ResourceIdentifier class identifies the type of resource for an entity resolver to identify.

When you configure a matlab.io.xml.dom.Parser object to resolve entities by using a class derived from the matlab.io.xml.dom.EntityResolver class, and the parser encounters an entity, the parser creates a matlab.io.xml.dom.ResourceIdentifier object. You can access the ResourceIdentifier object in the resolveEntity method of your entity resolver. Use the ResourceIdentifier object to determine the resolution of an entity.

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

Class Attributes

ConstructOnLoad
true
HandleCompatible
true

For information on class attributes, see Class Attributes.

Properties

expand all

Public ID of the resource, specified as a string scalar.

Attributes:

GetAccess
public
SetAccess
private
GetObservable
true
SetObservable
true

System ID of resource, specified as a string scalar.

Attributes:

GetAccess
public
SetAccess
private
GetObservable
true
SetObservable
true

Location of schema, specified as a string scalar.

Attributes:

GetAccess
public
SetAccess
private
GetObservable
true
SetObservable
true

URI of the namespace for the entities to be resolved, specified as a string scalar.

Attributes:

GetAccess
public
SetAccess
private
GetObservable
true
SetObservable
true

Base URI of resource, specified as a string scalar.

Attributes:

GetAccess
public
SetAccess
private
GetObservable
true
SetObservable
true

Methods

expand all

Examples

collapse all

This example creates an entity resolver, configures a parser to use the resolver, and parses an XML file that includes an entity reference.

The example uses these files:

  • chapter.xml contains markup for a chapter.

<?xml version="1.0" encoding="UTF-8"?>
<chapter><title color="red">Introduction</title></chapter>
  • book.xml contains the entity reference &chapter; and declares that the resource for the entity is chapter.xml.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book [
<!ENTITY chapter SYSTEM "chapter.xml">
]>
<book>
    &chapter;
</book>
  • BookEntityResolver is a subclass of the abstract class matlab.io.xml.dom.EntityResolver.

classdef BookEntityResolver < matlab.io.xml.dom.EntityResolver
    
    properties
        BaseDir
    end
    
    methods
        
        function obj =  BookEntityResolver(baseDir)
            obj@matlab.io.xml.dom.EntityResolver()
            obj.BaseDir = baseDir;
        end
        
        function res = resolveEntity(obj,ri)
            import matlab.io.xml.dom.ResourceIdentifierType
            if getResourceIdentifierType(ri) == ResourceIdentifierType.ExternalEntity
                res = fullfile(obj.BaseDir, ri.SystemID);
            end
        end
    end
    
end

Create an entity resolver as an instance of the BookEntityResolver class.

import matlab.io.xml.dom.*

resolver = BookEntityResolver(pwd);

Create a parser and configure it to use the resolver.

p = Parser();
p.Configuration.EntityResolver = resolver;
p.Configuration.AllowDoctype = true;

Parse the file book.xml into a matlab.io.xml.dom.Document object.

domDoc = parseFile(p,"book.xml");

To see that the chapter entity was resolved, find the chapter element node in the document.

nl = getElementsByTagName(domDoc,"chapter");
ch = node(nl,1)
ch = 
  Element with properties:

          TagName: 'chapter'
    HasAttributes: 0
      TextContent: 'Introduction'
         Children: [1×1 matlab.io.xml.dom.Element]

Version History

Introduced in R2021a