Main Content

matlab.io.xml.dom.Attr class

Package:matlab.io.xml.dom

Attribute of XML element

Description

Amatlab.io.xml.dom.Attrobject represents an attribute of an XML element.

Thematlab.io.xml.dom.Attrclass is ahandleclass.

Class Attributes

ConstructOnLoad
true
HandleCompatible
true

For information on class attributes, seeClass Attributes.

Creation

Create amatlab.io.xml.dom.Attrobject by using one of these approaches:

Properties

expand all

Whether this attribute is an ID attribute, specified astrueorfalse.

如果an element has an ID attribute with a unique value, you can use thegetElementByIDmethod of the document to access the element.

Attributes:

GetAccess
公共
SetAccess
immutable
Transient
true
NonCopyable
true

Name of this attribute, specified as a character vector.

Attributes:

GetAccess
公共
SetAccess
immutable
Transient
true
NonCopyable
true

Value of this attribute, specified as a character vector or string scalar.

Attributes:

GetAccess
公共
SetAccess
公共
NonCopyable
true

Methods

expand all

Examples

collapse all

This example creates and adds amatlab.io.xml.dom.Attrobject to amatlab.io.xml.dom.Elementobject by using thesetAttributemethod of theElementobject.

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 aColorattribute 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);

This example creates an attribute using thecreateAttributemethod of the owner document and adds the attribute to an element using thesetAttributeNodemethod 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 attributeColorand set the attribute value.

attrObj = createAttribute(doc,"Color"); setValue(attrObj,"red");

Add theColorattribute 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

Introduced in R2021a