matlab.io.xml.dom.Attr Class
Namespace: matlab.io.xml.dom
Description
A matlab.io.xml.dom.Attr
object represents an attribute of an XML
element.
The matlab.io.xml.dom.Attr
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.Attr
object by using one of these approaches:
Create an
Attr
object by using thecreateAttribute
orcreateAttributeNS
methods of amatlab.io.xml.dom.Document
object. Add theAttr
object to amatlab.io.xml.dom.Element
object by using thesetAttributeNode
orsetAttributeNodeNS
methods of theElement
object.Create and add an
Attr
object to amatlab.io.xml.dom.Element
object by using thesetAttribute
orsetAttributeNS
methods of theElement
object.
Properties
IsID
— Whether attribute is ID attribute
false
(default) | true
Whether this attribute is an ID attribute, specified as true
or
false
.
If an element has an ID attribute with a unique value, you can use the
getElementByID
method of the document to access the element.
Attributes:
GetAccess | public |
SetAccess | immutable |
Transient | true |
NonCopyable | true |
Name
— Attribute name
character vector
Name of this attribute, specified as a character vector.
Attributes:
GetAccess | public |
SetAccess | immutable |
Transient | true |
NonCopyable | true |
Value
— Attribute value
character vector | string scalar
Value of this attribute, specified as a character vector or string scalar.
Attributes:
GetAccess | public |
SetAccess | public |
NonCopyable | true |
Methods
Public Methods
cloneNode |
|
compareDocumentPosition |
For example: import matlab.io.xml.dom.* d = Document('root'); root = getDocumentElement(d); setAttribute(root,"Color","red"); a = getAttributeNode(root,"Color"); pos = compareDocumentPosition(a,root); if bitor(pos,a.DOCUMENT_POSITION_CONTAINS) == pos disp("root contains color attribute"); else disp("root does not contain color attribute"); end |
getBaseURI |
The base URI of an attribute node is the URI of the document that owns the attribute node. |
getLength |
|
getLocalName |
|
getNextSibling |
|
getName | name = getName(thisAttr) returns the name of this attribute
as a character vector. For example, if the name of this attribute is
'color' , this method returns
'color' . |
getNamespaceURI |
|
getNodeName | name = getNodeName(thisAttr) returns the name of this
attribute as a character vector. For example, if the name of this attribute is
'color' , this method returns
'color' . |
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('root'); root = getDocumentElement(d); setAttribute(root,"Color","red"); attrNode = getAttributeNode(root,"Color") if isa(attrNode,'matlab.io.xml.dom.Attr') fprintf('This is an attribute node.\n'); end |
getNodeTypeName | name = getNodeTypeName(thisAttr) returns
'ATTRIBUTE_NODE' . |
getNodeValue |
|
getOwnerElement |
|
getOwnerDocument |
|
getParentNode | parent = getParentNode(thisAttr) returns an empty node
because attributes are not children. |
getPrefix |
|
getPreviousSibling |
|
getSchemaTypeInfo |
|
getSpecified |
|
getTextContent | getTextContent(thisAttr) returns the value of this attribute
as a character vector. |
getValue | getValue(thisAttr) returns the value of this attribute as a
character vector. |
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. |
isID |
If an element has an ID attribute
with a unique value, you can use the |
isSameNode |
|
lookupNamespaceURI |
|
lookupPrefix |
|
setNodeValue |
Specify
|
setTextContent |
Specify |
setValue |
Specify |
Examples
Add an Attribute to an Element
This example creates and adds a matlab.io.xml.dom.Attr
object to a matlab.io.xml.dom.Element
object by using the setAttribute
method of the Element
object.
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 the root element para
.
doc = Document("para");
para = getDocumentElement(doc);
Add a Color
attribute to the para
element.
setAttribute(para,"Color","red");
Add text to the para
element.
textNode = createTextNode(doc,"Hello");
appendChild(para,textNode);
Write the XML to a file.
xmlFileName = "para.xml";
writer = matlab.io.xml.dom.DOMWriter;
writeToFile(writer,doc,xmlFileName);
Create an Attribute and Add It to an Element
This example creates an attribute using the createAttribute
method of the owner document and adds the attribute to an element using the setAttributeNode
method of the element.
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 the root element para
.
doc = Document("para");
para = getDocumentElement(doc);
Create an attribute Color
and set the attribute value.
attrObj = createAttribute(doc,"Color"); setValue(attrObj,"red");
Add the Color
attribute to the para
element.
setAttributeNode(para,attrObj);
Create a text node and add it to the para
element.
textNode = createTextNode(doc,"Hello");
appendChild(para,textNode);
Write the XML to a file.
xmlFileName = "para.xml";
writer = matlab.io.xml.dom.DOMWriter;
writeToFile(writer,doc,xmlFileName);
Version History
Introduced in R2021a
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de 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)