Main Content

matlab.io.xml.dom.Entity class

Package: matlab.io.xml.dom

Entity defined by document type

Description

An object of the matlab.io.xml.dom.Entity class represents an XML entity. An XML entity is document content that has a name and is defined by a document type definition associated with a document. The getEntities method of a matlab.io.xml.dom.DocumentType object returns a list of the entities defined by the document type as a matlab.io.xml.dom.NamedNodeMap object. Use the item method of the NamedNodeMap object to return an Entity object that is in the list.

Note

An Entity object inherits methods and properties from the matlab.io.xml.dom.Node class that are ineffective or cause errors when used with an Entity object. Use only the methods and properties documented on this page.

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

Class Attributes

ConstructOnLoad
true
HandleCompatible
true

For information on class attributes, see Class Attributes.

Properties

expand all

Encoding of the entity source document, specified as a character vector.

Attributes:

GetAccess
public
SetAccess
immutable
Transient
true
NonCopyable
true

Public ID of the entity source document, specified as a character vector. The property value is set to the public ID specified by the document type declaration from which this entity was parsed.

Attributes:

GetAccess
public
SetAccess
immutable
Transient
true
NonCopyable
true

System ID of the entity source document, specified as a character vector. The property value is set to the location specified by the document type declaration from which this entity was parsed.

Attributes:

GetAccess
public
SetAccess
immutable
Transient
true
NonCopyable
true

Encoding specified by the XML declaration in the source file from which this entity was parsed, specified as a character vector.

Attributes:

GetAccess
public
SetAccess
immutable
Transient
true
NonCopyable
true

XML version specified by the XML declaration in the source file from which this entity was parsed, specified as a character vector.

Attributes:

GetAccess
public
SetAccess
immutable
Transient
true
NonCopyable
true

Methods

expand all

Examples

collapse all

This example shows how to access document type and entity information in a DOM document that was parsed from XML markup that contains a document type definition (DTD).

The example uses these files, which must all be in the same folder:

  • book.xml contains a document type definition that declares that the resource for the chapter entity is chapter.xml.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book [
<!ENTITY chapter SYSTEM "chapter.xml">
]>
<book>
    &chapter;
</book>
  • chapter.xml contains markup for a chapter.

<?xml version="1.0" encoding="UTF-8"?>
<chapter><title color="red">Introduction</title></chapter>

Parse the XML into a matlab.io.xml.dom.Document object.

import matlab.io.xml.dom.*

doc = parseFile(Parser,'book.xml');

To get information about the document type, use the getDoctype method of the Document object.

docTypeObj = getDoctype(doc)
docTypeObj = 
  DocumentType with properties:

              Name: 'book'
          PublicID: ''
          SystemID: ''
    InternalSubset: '...'
       TextContent: ''
          Children: [1x0 matlab.io.xml.dom.Node]

To get information about the entities defined by the document type, use the getEntities method of the DocumentType object. The method returns a list of the entities as a NamedNodeMap object.

namedNodeMapObj = getEntities(docTypeObj);

To return the matlab.io.xm.dom.Entity objects that represent the entities, use the item method of the NamedNodeMap object. Specify the first index as 0.

n = getLength(namedNodeMapObj)-1;
for i=0:n
    item(namedNodeMapObj,i)
end
ans = 
  Entity with properties:

    InputEncoding: 'UTF-8'
         PublicID: ''
         SystemID: 'chapter.xml'
      XMLEncoding: 'UTF-8'
       XMLVersion: '1.0'
      TextContent: '...'
         Children: [1x2 matlab.io.xml.dom.Node]

Introduced in R2021a