matlab.io.xml.dom.Attr class
Package:matlab.io.xml.dom
Attribute of XML element
Description
Amatlab.io.xml.dom.Attr
object represents an attribute of an XML element.
Thematlab.io.xml.dom.Attr
class is ahandle
class.
Class Attributes
ConstructOnLoad |
true
|
HandleCompatible |
true
|
For information on class attributes, seeClass Attributes.
Creation
Create amatlab.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 astrue
orfalse
.
如果an element has an ID attribute with a unique value, you can use thegetElementByID
method of the document to access the element.
Attributes:
GetAccess |
公共
|
SetAccess |
immutable
|
Transient |
true
|
NonCopyable |
true
|
Name
—Attribute name
character vector
Name of this attribute, specified as a character vector.
Attributes:
GetAccess |
公共
|
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 |
公共
|
SetAccess |
公共
|
NonCopyable |
true
|
Methods
Public Methods
cloneNode |
|
compareDocumentPosition |
For example: importmatlab.io.xml.dom.*d = Document('root'); root = getDocumentElement(d); setAttribute(root,"Color","red"); a = getAttributeNode(root,"Color"); pos = compareDocumentPosition(a,root);ifbitor(pos,a.DOCUMENT_POSITION_CONTAINS) == pos disp("root contains color attribute");elsedisp("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 importmatlab.io.xml.dom.*d = Document('root'); root = getDocumentElement(d); setAttribute(root,"Color","red"); attrNode = getAttributeNode(root,"Color")ifisa(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 |
巴勒斯坦权力机构rent = 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 |
如果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 amatlab.io.xml.dom.Attr
object to amatlab.io.xml.dom.Element
object by using thesetAttribute
method of theElement
object.
Import thematlab.io.xml.dom
巴勒斯坦权力机构ckage so that you do not have to use long, fully qualified class names.
importmatlab.io.xml.dom.*
Create a document with the root element帕拉
.
doc = Document("para"); para = getDocumentElement(doc);
Add aColor
attribute to the帕拉
element.
setAttribute(para,"Color","red");
Add text to the帕拉
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 thecreateAttribute
method of the owner document and adds the attribute to an element using thesetAttributeNode
method of the element.
Import thematlab.io.xml.dom
巴勒斯坦权力机构ckage so that you do not have to use long, fully qualified class names.
importmatlab.io.xml.dom.*
Create a document with the root element帕拉
.
doc = Document("para"); para = getDocumentElement(doc);
Create an attributeColor
and set the attribute value.
attrObj = createAttribute(doc,"Color"); setValue(attrObj,"red");
Add theColor
attribute to the帕拉
element.
setAttributeNode(para,attrObj);
Create a text node and add it to the帕拉
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);
版本;n History
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
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)