matlab.io.xml.dom.Document Class
Namespace: matlab.io.xml.dom
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(
creates a document with a root element that has the specified name.docElemName
)
The root element is a matlab.io.xml.dom.Element
object with the TagName
property
set to docElemName
.
doc = matlab.io.xml.dom.Document(
also specifies the document type.docElemName
,docTypeName
,publicId
,systemId
)
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(
creates a document with a root element that has the specified namespace Uniform Resource
Identifier (URI) and qualified name.docElemNSURI
,docElemQName
)
doc = matlab.io.xml.dom.Document(
creates a document with the specified root element and document type where the
root element resides in the specified namespace.docElemNSURI
,docElemQName
,docTypeName
,publicId
,systemId
)
Input Arguments
docElemName
— Root element name
character vector | string scalar
Root element name, specified as a character vector or string scalar.
docTypeName
— Name of DTD
character vector | string scalar
Name of Document Type Definition (DTD), specified as a character vector or string scalar.
publicId
— Document type public identifier
character vector | string scalar
Document type public identifier, specified as a character vector or string scalar.
systemId
— Document type system identifier
character vector | string scalar
Document type system identifier, specified as a character vector or string scalar.
docElemNSURI
— Namespace URI for root element name
character vector | string scalar
Namespace Uniform Resource Identifier (URI) for root element name, specified as a character vector or string scalar.
docElemQName
— Qualified root element name
character vector | string scalar
Qualified root element name, specified as a character vector or string scalar.
Properties
Children
— Child node of this document
1-by-0 matlab.io.xml.dom.Node
object (default) | matlab.io.xml.dom.Element
object
Child node of this document, specified as a matlab.io.xml.dom.Element
object.
Attributes:
GetAccess | public |
SetAccess | immutable |
NonCopyable | true |
Transient | true |
InputEncoding
— Character encoding of source XML
''
(default) | character vector
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 |
XMLEncoding
— Character encoding defined by XML declaration
''
(default) | character vector
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 |
XMLStandalone
— Whether this document is standalone
false
(default) | 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 |
XMLVersion
— XML version of this document
''
(default) | character vector
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 |
DocumentURI
— URI of document source file
''
(default) | character vector
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 |
Configuration
— Document configuration
matlab.io.xml.dom.DocumentConfiguration
object
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
Public Methods
appendChild |
| ||||||||||||||
cloneNode |
| ||||||||||||||
createAttribute |
| ||||||||||||||
createAttributeNS |
| ||||||||||||||
createComment |
| ||||||||||||||
createDocumentFragment | frag = createDocumentFragment(thisDoc) creates and returns a
document fragment as a matlab.io.xml.dom.DocumentFragment object. | ||||||||||||||
createElement |
Specify | ||||||||||||||
createElementNS |
Specify
| ||||||||||||||
createNSResolver |
| ||||||||||||||
createProcessingInstruction |
| ||||||||||||||
createTextNode |
| ||||||||||||||
getAttributes |
This method provides compatibility with existing MATLAB® code that is based on the W3C XML DOM standard. | ||||||||||||||
getBaseURI |
| ||||||||||||||
getChildNodes |
| ||||||||||||||
getChildren |
| ||||||||||||||
getDoctype |
| ||||||||||||||
getDocumentElement |
The root element contains the content of the document. | ||||||||||||||
getDocumentURI |
You can use the | ||||||||||||||
getDOMConfig |
| ||||||||||||||
getElementByID |
An ID attribute is an attribute that is declared to be
an ID attribute. An attribute with the name | ||||||||||||||
getElementsByTagName |
The returned | ||||||||||||||
getElementsByTagNameNS |
The returned | ||||||||||||||
getFirstChild | child = getFirstChild(thisNode) returns the first child of
this document. | ||||||||||||||
getInputEncoding |
| ||||||||||||||
getLastChild | child = getLastChild(thisDoc) returns the last child of this
document. | ||||||||||||||
getLocalName |
| ||||||||||||||
getNamespaceURI |
This method provides compatibility with existing MATLAB code that is based on the W3C XML DOM standard. | ||||||||||||||
getNextSibling |
This method provides compatibility with existing MATLAB code that is based on the W3C XML DOM standard. | ||||||||||||||
getNodeName |
This method provides compatibility with existing MATLAB code that is based on the W3C XML DOM standard. | ||||||||||||||
getNodeType |
This method provides compatibility with existing MATLAB code that is based on the W3C XML DOM standard. For new
MATLAB code, use import matlab.io.xml.dom.* d = Document('book'); if isa(d,'matlab.io.xml.dom.Document') fprintf('This is a document.\n'); end | ||||||||||||||
getNodeValue |
This method provides compatibility with existing MATLAB code that is based on the W3C XML DOM standard. | ||||||||||||||
getOwnerDocument |
| ||||||||||||||
getParentNode | parent = getParentNode(thisDoc) returns a 0-by-0
matlab.io.xml.dom.Node object because a document does not have a
parent node. | ||||||||||||||
getPrefix |
This method provides compatibility with existing MATLAB code that is based on the W3C XML DOM standard. | ||||||||||||||
getPreviousSibling |
This method provides compatibility with existing MATLAB code that is based on the W3C XML DOM standard. | ||||||||||||||
getTextContent | getTextContent(thisDoc) returns an empty character array
because a document does not have text. | ||||||||||||||
getXmlEncoding |
The character encoding can be defined by an XML
declaration in the file from which a | ||||||||||||||
getXMLStandalone |
You can specify that a document is
standalone by using an XML declaration in the file from which a
| ||||||||||||||
getXMLVersion |
You can specify the
XML version by using an XML declaration in the file from which a
| ||||||||||||||
hasAttributes |
This method provides compatibility with existing MATLAB code that is based on the W3C XML DOM standard. | ||||||||||||||
hasChildNodes |
| ||||||||||||||
importNode | Import node from another document into this document. See | ||||||||||||||
isDefaultNamespace |
A default namespace is declared without a prefix. Child nodes
of the document with names that lack a prefix belong to the default workspace. To
declare a default namespace for a document, you can use the
import matlab.io.xml.dom.* nsURI = "http://my.namespace.org/mybook"; d = Document(nsURI,'book'); if isDefaultNamespace(d,nsURI) fprintf(... '"%s" is the default namepace\n',nsURI); end | ||||||||||||||
isEqualNode |
This
method tests for equality of documents, not whether the documents nodes are
handles to the same object. To test for sameness, use
Nodes that are the same are also equal, but node that are equal are not necessarily the same. Normalize documents before testing them for equality because normalization can affect equality. | ||||||||||||||
isSameNode |
| ||||||||||||||
lookupNamespaceURI |
This method provides compatibility with existing MATLAB code that is based on the W3C XML DOM standard. | ||||||||||||||
lookupPrefix |
This method provides compatibility with existing MATLAB code that is based on the W3C XML DOM standard. | ||||||||||||||
normalize |
| ||||||||||||||
normalizeDocument | normalizeDocument(thisDoc) normalizes this document.
Normalization ensures that the document structure is the same as the structure after
saving and reloading the document. For example, the method removes empty text nodes,
merges adjacent text nodes, adds missing namespace attributes, adds or changes
prefixes, and updates the replacement trees of entity reference nodes. The
normalization operations performed by this method depend on the options specified by
the matlab.io.xml.dom.DocumentConfiguration object used by the
document. | ||||||||||||||
removeChild |
| ||||||||||||||
replaceChild |
| ||||||||||||||
renameNode |
Specify:
| ||||||||||||||
setDocumentURI |
| ||||||||||||||
setNodeValue |
| ||||||||||||||
setPrefix |
| ||||||||||||||
setTextContent |
| ||||||||||||||
setXMLStandalone |
| ||||||||||||||
xmlwrite |
|
Examples
Create a Document from an XML File
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
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
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)