matlab.io.xml.dom.Entity class
Package: matlab.io.xml.dom
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
InputEncoding
— Encoding of entity source document
character vector
Encoding of the entity source document, specified as a character vector.
Attributes:
GetAccess | public |
SetAccess | immutable |
Transient | true |
NonCopyable | true |
PublicID
— Public ID of entity source document
character vector
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 |
SystemID
— System ID of entity source document
character vector
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 |
XMLEncoding
— Encoding specified by XML declaration
character vector
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 |
XMLVersion
— XML version specified by XML declaration
character vector
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
Public Methods
getInputEncoding |
|
getNodeName |
|
getNotationName |
The method returns an empty character vector for character entities and for entities that specify parsed files, such as XML files. |
getPublicID |
|
getSystemID |
|
getXMLEncoding |
|
getXMLVersion |
|
Examples
Access Document Type and Entities in Parsed Document
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 thechapter
entity ischapter.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
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)