Main Content

matlab.io.xml.dom.DocumentType Class

Namespace: matlab.io.xml.dom

Document type

Since R2021a

Description

An object of the matlab.io.xml.dom.DocuementType class represents a document type.

The getDoctype method of a matlab.io.xml.dom.Document object returns a matlab.io.xml.dom.DocumentType object if the Document object was created by a parser from XML markup that contains a document type definition (DTD).

Note

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

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

Class Attributes

ConstructOnLoad
true
HandleCompatible
true

For information on class attributes, see Class Attributes.

Properties

expand all

Name of the document type, specified as a character vector.

Attributes:

GetAccess
public
SetAccess
immutable
Transient
true
NonCopyable
true

Public id of the document type, specified as a character vector.

Attributes:

GetAccess
public
SetAccess
immutable
Transient
true
NonCopyable
true

System id of the document type, specified as a character vector.

Attributes:

GetAccess
public
SetAccess
immutable
Transient
true
NonCopyable
true

Locally defined entities and notations, specified as a character vector. Locally defined entities and notations are defined in the markup from which the document type was parsed.

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.*

myParser = Parser;
myParser.Configuration.AllowDoctype = true;
doc = parseFile(myParser,'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: '↵<!ENTITY chapter SYSTEM "chapter.xml">↵'
       TextContent: ''
          Children: [1×0 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: '↵Introduction'
         Children: [1×2 matlab.io.xml.dom.Node]

Version History

Introduced in R2021a