Main Content

matlab.io.xml.dom.Document Class

Namespace: matlab.io.xml.dom

XML Document

Since R2021a

Description

An object of the matlab.io.xml.dom.Document class represents an XML document. To create an XML document, you create a Document object. If you use a matlab.io.xml.dom.Parser object to read an XML file, the parser creates a Document object.

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

Class Attributes

ConstructOnLoad
true
HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

doc = matlab.io.xml.dom.Document() creates an empty document.

doc = matlab.io.xml.dom.Document(docElemName) creates a document with a root element that has the specified name.

The root element is a matlab.io.xml.dom.Element object with the TagName property set to docElemName.

example

doc = matlab.io.xml.dom.Document(docElemName,docTypeName,publicId,systemId) also specifies the document type.

The document type is a matlab.io.xml.dom.DocumentType object with the Name property set to docTypeName, the PublicID property set to publicID, and the SystemID property set to systemID.

doc = matlab.io.xml.dom.Document(docElemNSURI,docElemQName) creates a document with a root element that has the specified namespace Uniform Resource Identifier (URI) and qualified name.

doc = matlab.io.xml.dom.Document(docElemNSURI,docElemQName,docTypeName,publicId,systemId) creates a document with the specified root element and document type where the root element resides in the specified namespace.

Input Arguments

expand all

Root element name, specified as a character vector or string scalar.

Name of Document Type Definition (DTD), specified as a character vector or string scalar.

Document type public identifier, specified as a character vector or string scalar.

Document type system identifier, specified as a character vector or string scalar.

Namespace Uniform Resource Identifier (URI) for root element name, specified as a character vector or string scalar.

Qualified root element name, specified as a character vector or string scalar.

Properties

expand all

Child node of this document, specified as a matlab.io.xml.dom.Element object.

Attributes:

GetAccess
public
SetAccess
immutable
NonCopyable
true
Transient
true

Character encoding of the source XML file from which this document was parsed, specified as a character vector.

Example: 'utf-8'

Attributes:

GetAccess
public
SetAccess
immutable
Transient
true
NonCopyable
true

Character encoding defined by a XML declaration in the source XML file from which this document was parsed, specified as a character vector.

Example: 'utf-8'

Attributes:

GetAccess
public
SetAccess
immutable
Transient
true
NonCopyable
true

Whether this document is standalone, specified as true or false. If this value is true, a parser ignores Document Type Definition (DTD) markup declarations in the XML. If this document is created from XML source that declares that the XML is standalone, the parser sets this property to true.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

XML version of this document, specified as a character vector. If this document is created from XML source that declares the XML version, the parser sets this property to the specified version.

Example: '1.0'

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Universal Resource Identifier (URI) of the document source file, specified as a character vector. If this document is created from a file, the parser sets this property to a URI that specifies the location of the file.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Document configuration, specified as a matlab.io.xml.dom.DocumentConfiguration object that specifies options for normalizing this document.

Attributes:

GetAccess
public
SetAccess
immutable
NonCopyable
true
Transient
true

Methods

expand all

Examples

collapse all

Use an XML parser to create a Document object from the file days.xml.

import matlab.io.xml.dom.*

doc = parseFile(Parser,"days.xml");

Create a document with a root element named weekdays. Append content to the root element.

import matlab.io.xml.dom.*
doc = Document("weekdays");
docRootNode = getDocumentElement(doc);

weekdays = ["Mon" "Tue" "Wed" "Thu" "Fri"];
for i=1:5
    dayElement = createElement(doc,"day");
    appendChild(dayElement,createTextNode(doc,weekdays(i)));
    appendChild(docRootNode,dayElement);
end

xmlFileName = "weekdays.xml";
writer = matlab.io.xml.dom.DOMWriter;
writeToFile(writer,doc,xmlFileName);

Version History

Introduced in R2021a