Entity defined by document type
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
Entity object inherits methods and properties from the
matlab.io.xml.dom.Node class that are ineffective or cause errors when used
Entity object. Use only the methods and properties documented on this
matlab.io.xml.dom.Entity class is a
For information on class attributes, see Class Attributes.
InputEncoding— Encoding of entity source document
Encoding of the entity source document, specified as a character vector.
PublicID— Public ID of entity source document
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.
SystemID— System ID of entity source document
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.
XMLEncoding— Encoding specified by XML declaration
Encoding specified by the XML declaration in the source file from which this entity was parsed, specified as a character vector.
XMLVersion— XML version specified by XML declaration
XML version specified by the XML declaration in the source file from which this entity was parsed, specified as a character vector.
The method returns an empty character vector for character entities and for entities that specify parsed files, such as XML files.
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
<?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
import matlab.io.xml.dom.* doc = parseFile(Parser,'book.xml');
To get information about the document type, use the
getDoctype method of the
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
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]