Chapter 3 DynaScript Predefined Objects
Represents an attribute in an XML element.
The XML element itself is represented by a DOMElement
object.
To use a DOMAttribute's property:
DOMAttribute.propertyName
To use a DOMAttribute's method:
DOMAttribute.MethodName( parameter )
DOMAttribute
objects
inherit the properties and methods of the DOMNode
object.
The attributes for a particular DOMElement
are
accessible via the attributes
property
of the DOMElement
object.
The parentNode
, previousSibling
,
and nextSibling
properties
of a DOMAttribute
object
are null.
The children of the DOMAttribute
object
represent the attribute's value. Attributes whose values
are inferred from the DTD are not yet supported and do not appear
within the document tree.
DOMAttribute
objects
have all of the properties and methods of the DOMNode
object
as well as the properties defined here.
To obtain a DOMAttribute object in an existing
document, you can use the getAttributeNode method
of a DOMElement object, or the attributes
property
of a DOMNode object.
To add a DOMAttribute object to a DOM document, you can use the setAttributeNode method of a DOMElement object.
DOMAttribute.name
Returns the name of the attribute.
For the following start tag of an element:
<Region Type="State">
there is one attribute, which has the name Type.
The following DynaScript fragment writes out
the name of each attribute of a DOMElement
object
named elem:
attlist = elem.attributes for( iAtt=0; iAtt < attlist.length; iAtt++ ) { document.writeln( attlist.item(iAtt).name ); }
DOMAttribute.specified
This property is read-only.
If the attribute was explicitly given a value in the original document, the specified property is set to true. If no value was given, the specified property is set to false.
This property is set to true if the value of the attribute is changed.
Attributes whose values are not explicitly specified, but are instead inferred from the DTD are not yet supported and do not appear within the document tree. Therefore, for attributes within the document tree, this property is always true.
This example writes out the name of each specified
attribute of a DOMElement
object
named elem:
attlist = elem.attributes for( iAtt=0; iAtt < attlist.length; iAtt++ ) { if( attlist.item(iAtt).specified == true ){ document.writeln( attlist.item(iAtt).name ); } }
DOMAttribute.value
This property is read/write.
When retrieved, this property returns the attribute value as a string. Entity references will be replaced by their values.
When set, a DOMText
object
representing the string is created, and will become the only child
of the DOMAttribute
object.
For the following start tag of an element:
<Region Type="State">
there is one attribute, which has the value State.
This DynaScript fragment writes out the value
of each specified attribute of a DOMElement
object
named elem:
attlist = elem.attributes for( iAtt=0; iAtt < attlist.length; iAtt++ ) { document.writeln( attlist.item(iAtt).value ); } }
Copyright © 2001 Sybase, Inc. All rights reserved. |
![]() |