matlab.io.xml.dom.Text Class
Namespace: matlab.io.xml.dom
Description
An object of the matlab.io.xml.dom.Text
class represents the text content
of an XML document.
The matlab.io.xml.dom.Text
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.Text
object by using the
createTextNode
method of a matlab.io.xml.dom.Document
object.
Properties
Length
— Number of characters in text
double
Number of characters in the text content of this node, specified as a double.
Attributes:
GetAccess | public |
SetAccess | immutable |
Transient | true |
NonCopyable | true |
TextContent
— Text content of text node
character vector
Text content of this text node, specified as a character vector.
Attributes:
GetAccess | public |
SetAccess | public |
NonCopyable | true |
Methods
Public Methods
appendData |
Specify
|
cloneNode |
|
compareDocumentPosition |
For example: import matlab.io.xml.dom.* d = Document("root"); root = getDocumentElement(d); text = createTextNode(d,"Hello"); appendChild(root,text); pos = compareDocumentPosition(text,root); if bitor(pos,text.DOCUMENT_POSITION_CONTAINS) == pos disp("root contains text"); else disp("root does not contain text"); end |
deleteData |
|
getBaseURI |
The base URI of a text node is the URI of the document that owns the text node. |
getData |
|
getLength |
|
getNextSibling |
|
getNodeName | name = getNodeName(thisText) returns
'#text' . |
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"); txt = createTextNode(d,"hello"); if isa(txt,'matlab.io.xml.dom.Text') fprintf('This is a text node.\n'); end |
getNodeTypeName | name = getNodeTypeName(thisText) returns
'TEXT_NODE' . |
getNodeValue |
|
getOwnerDocument |
|
getParentNode | parent = getParentNode(thisText) returns the parent node of
this text node. If this text node does not have a parent, the method returns an
empty node. |
getPreviousSibling |
|
getTextContent | getTextContent(thisText) returns the text content of this
text node as a character vector. |
insertData |
|
isEqualNode |
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 |
|
replaceData |
Specify |
setData |
Specify |
setNodeValue |
Specify |
setTextContent |
Specify |
splitText |
|
substringData |
Specify |
Examples
Create a Text Node for an XML DOM Document
Create a text node to append to a document element by using the createTextNode
method of the matlab.io.xml.dom.Document
object that represents the document.
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 with a root element named employee
.
doc = Document("employee");
employeeElem = getDocumentElement(doc);
Create an element named jobtitle
.
jobtitleElem = createElement(doc,"jobtitle");
Create a text node for the jobtitle
text content and append the text note to the jobtitle
element.
textNode = createTextNode(doc,"Manager");
appendChild(jobtitleElem,textNode);
Append the jobtitle
element to the employeeElem
element.
appendChild(employeeElem,jobtitleElem);
Write the XML to a file.
xmlFileName = "employee.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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)