matlab.io.xml.dom.Element class
Package: matlab.io.xml.dom
Element of XML document
Description
An object of the matlab.io.xml.dom.Element
class represents an XML markup
tag.
The matlab.io.xml.dom.Element
class is a handle
class.
Class Attributes
ConstructOnLoad | true |
HandleCompatible | true |
For information on class attributes, see Class Attributes.
Creation
Create a matlab.io.xml.dom.Element
object by using the
createElement
or createElementNS
method of a matlab.io.xml.dom.Document
object.
Properties
Children
— Child nodes of this element
1-by-N array of child nodes
Child nodes of this element, specified as a 1-by-N array of
matlab.io.xml.dom
objects.
Attributes:
GetAccess | public |
SetAccess | immutable |
NonCopyable | true |
Transient | true |
TagName
— Tag name of element
character vector
Tag name of this element, specified as a character vector.
Attributes:
GetAccess | public |
SetAccess | immutable |
NonCopyable | true |
Transient | true |
TextContent
— Text content of element
''
(default) | character vector | string scalar
Text content of this element, specified as a character vector or string scalar. This property contains the concatenated textual content of this node and its children.
Attributes:
GetAccess | public |
SetAccess | public |
NonCopyable | true |
HasAttributes
— Whether this element has attributes
false
(default) | true
Whether this element has attributes, specified as true
or
false
.
Attributes:
GetAccess | public |
SetAccess | immutable |
NonCopyable | true |
Transient | true |
Methods
Public Methods
appendChild |
|
cloneNode |
|
compareDocumentPosition |
For example: import matlab.io.xml.dom.* d = Document("root"); root = getDocumentElement(d); para = createElement(d,"para"); appendChild(root,para); pos = compareDocumentPosition(para,root); if bitor(pos,para.DOCUMENT_POSITION_CONTAINS) == pos disp("root contains paragraph"); else disp("root does not contain paragraph"); end |
getAttribute |
Specify
|
getAttributeNode |
Specify
|
|
Specify
|
getAttributeNS |
Specify |
getAttributes |
|
getBaseURI |
The base URI of an element is the URI of the document that owns the element. |
getChildElementCount |
|
getChildNodes |
|
getChildren |
|
getElementsByTagName |
The
|
getElementsByTagNameNS |
The |
getFirstChild | child = getFirstChild(thisElem) returns the first child of
this element. |
getFirstElementChild |
|
getLastChild | child = getLastChild(thisElem) returns the last child of
this element. |
getLastElementChild |
|
getLocalName |
|
getNamespaceURI |
|
getNextSibling |
|
getNextElementSibling |
|
getNodeIndex |
|
getNodeName |
This method provides compatibility with existing
MATLAB® code that is based on the W3C XML DOM standard. In new code, use
|
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'); para = createElement(d,"para"); if isa(para,'matlab.io.xml.dom.Element') fprintf('This is an element.\n'); end |
getNodeTypeName | name = getNodeTypeName(thisElem) returns
'ELEMENT_NODE' . |
getNodeValue |
This method provides compatibility with existing MATLAB code that is based on the W3C XML DOM standard. |
getOwnerDocument |
|
getParentNode | parent = getParentNode(thisElem) returns the parent node of
this element. If this element does not have a parent, the method returns an empty
node . |
getPrefix |
|
getPreviousSibling |
|
getPreviousElementSibling |
|
getSchemaTypeInfo |
The
|
getTagName |
|
getTextContent | getTextContent(thisElem) returns the text content of this
element. If this element has children, this method returns the concatenated text
content of the children. |
hasAttribute |
|
hasAttributeNS |
|
hasAttributes |
|
hasChildNodes |
|
isDefaultNamespace |
A default namespace is an element namespace declared without
a prefix. The element and all its children whose names lack a prefix belong to the
default namespace. Use
import matlab.io.xml.dom.* nsURI = "http://my.namespace.org/mybook"; d = Document(nsURI,'book'); book = getDocumentElement(d); if isDefaultNamespace(book,nsURI) fprintf(... '"%s" is the default namespace\n',nsURI); end |
isEqualNode |
The property values are equal if they have the same length and are character-for-character equal. The node owner document and attribute values do not affect equality. This method tests for
equality of nodes, not whether the nodes are handles to the same object. To test
for sameness, use the Nodes that are the same are also equal, but nodes that are equal are not necessarily the same. Normalize documents before testing them for equality because normalization can affect equality. |
isSameNode |
|
lookupNamespaceURI |
|
lookupPrefix |
|
normalize |
Normalization ensures that the element structure is the same as the structure after saving and reloading the document that contains the element. |
removeAttribute |
|
removeAttributeNode |
|
removeAttributeNS |
|
removeChild |
|
replaceChild |
|
setAttribute |
Because the method treats the value as CDATA, the
method ignores markup text, including entity references, in the value string. To
set an attribute to a value that includes an entity reference, such as
|
setAttributeNode |
Specify |
setAttributeNodeNS |
Specify |
setAttributeNS |
Specify Because the method treats the value as CDATA, the
method ignores markup text, including entity references, in the value string. To
set an attribute to a value that includes an entity reference, such as
|
setIDAttribute |
Specify |
setIDAttributeNode |
Specify |
setIDAttributeNS |
Specify |
setNodeValue |
|
setTextContent |
Specify |
Examples
Create XML Elements and Text Nodes
This example creates matlab.io.xml.dom.Element
and matlab.io.xml.dom.Text
objects to represent XML markup for weekdays.
Import the matlab.io.xml.dom
package so that you do not have to use long, fully qualified class names.
import matlab.io.xml.dom.*
Create a document and the root element weekdays
.
doc = Document("weekdays");
weekdaysElement = getDocumentElement(doc);
Create a string array of the text for each weekday.
weekdays = ["Mon" "Tue" "Wed" "Thu" "Fri"];
For each weekday, create an Element
object for the day
element and a Text
object for the day text. Append the Text
object to the day
element and the day
element to the weekdays
element.
for i=1:5 dayElement = createElement(doc,"day"); appendChild(dayElement,createTextNode(doc,weekdays(i))); appendChild(weekdaysElement,dayElement); end
Write the XML to a file.
xmlFileName = "weekdays.xml";
writer = matlab.io.xml.dom.DOMWriter;
writeToFile(writer,doc,xmlFileName);
Version History
Introduced in R2021a
Ouvrir l'exemple
Vous possédez une version modifiée de cet exemple. Souhaitez-vous ouvrir cet exemple avec vos modifications ?
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
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)