- All Implemented Interfaces:
XMLAttributes,Attributes,Attributes2
- Direct Known Subclasses:
XMLAttributesImpl.EmptyXMLAttributesImpl
XMLAttributes
interface which defines a collection of attributes for an element. In the
parser, the document source scans the entire start element and collects
the attributes, communicating them to the document handler via the
startElement method.
The attributes are read-write so that subsequent stages in the document pipeline can modify values or change attributes propagated to the next stage.
- Author:
- Andy Clark, IBM, Elena Litani, IBM, Michael Glavassevich, IBM, Ronald Brill
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classINTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.static final classAn immutable, emptyXMLAttributesImplused as a flyweight for synthesized elements. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a defaultXMLAttributesImplinstance with an initial capacity.XMLAttributesImpl(XMLAttributesImpl attributes) Constructs a copy of the specified attribute collection. -
Method Summary
Modifier and TypeMethodDescriptionintaddAttribute(QName name, String type, String value) Adds an attribute.voidaddAttribute(QName name, String type, String value, boolean specified) Adds an attribute.voidaddAttribute(QName name, String type, String value, String nonNormalizedValue, boolean specified) Adds an attribute together with its non-normalized (plain) value.INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.intLooks up the index of an attribute by XML 1.0 qualified name.intLooks up the index of an attribute by Namespace name.intReturns the number of attributes in the list.getLocalName(int index) Looks up an attribute's local name by index.getName(int index) Returns the fullQNamestructure of the attribute at the specified index.voidPopulates the fields of the givenQNamestructure with the values of the attribute name at the specified index.getNameRawName(int index) INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.getNonNormalizedValue(int index) Returns the non-normalized value of the attribute at the specified index.getQName(int index) Looks up an attribute's XML 1.0 qualified name by index.getType(int index) Looks up an attribute's type by index.Looks up an attribute's type by XML 1.0 qualified name.Looks up an attribute's type by Namespace name.getURI(int index) Looks up an attribute's Namespace URI by index.getValue(int index) Looks up an attribute's value by index.Looks up an attribute's value by XML 1.0 qualified name.Looks up an attribute's value by Namespace name.booleanisDeclared(int index) booleanisDeclared(String qName) booleanisDeclared(String uri, String localName) booleanisSpecified(int attrIndex) Returns whether the attribute at the specified index was specified in the instance document.booleanisSpecified(String qName) booleanisSpecified(String uri, String localName) voidRemoves all attributes from the collection.voidremoveAttributeAt(int attrIndex) Removes the attribute at the specified index.voidSets the name of the attribute at the specified index.voidsetSpecified(int attrIndex, boolean specified) Sets whether an attribute was specified in the instance document.voidSets the value of the attribute at the specified index.
-
Constructor Details
-
XMLAttributesImpl
public XMLAttributesImpl()Constructs a defaultXMLAttributesImplinstance with an initial capacity. -
XMLAttributesImpl
Constructs a copy of the specified attribute collection.- Parameters:
attributes- the attribute collection to copy from
-
-
Method Details
-
addAttribute
Adds an attribute. The attribute's non-normalized value will have the same value as the attribute value. Also, the added attribute will be marked as specified in the XML instance document unless set otherwise using thesetSpecified(int, boolean)method.Note: This implementation does not check whether an attribute of the same name already exists. If duplicate prevention is required, the caller must verify uniqueness before calling this method.
- Specified by:
addAttributein interfaceXMLAttributes- Parameters:
name- the attribute nametype- the attribute type. The type name is determined by the type specified for this attribute in the DTD (e.g., "CDATA", "ID", "NMTOKEN", etc.). Enumeration types will have the type value specified as a pipe-separated list enclosed in parentheses, for example: "(true|false)".value- the attribute value- Returns:
- the zero-based attribute index
- See Also:
-
addAttribute
Adds an attribute. The attribute's non-normalized value will have the same value as the attribute value. Also, the added attribute will be marked as specified in the XML instance document unless set otherwise using thesetSpecified(int, boolean)method.This method differs from other addAttribute variants in that it does not check if an attribute of the same name already exists in the list before adding it. To improve performance of namespace processing, this method allows uniqueness checks to be deferred until all namespace information is available after the entire attribute specification has been read.
Caution: If this method is called, it should not be mixed with standard
addAttributecalls unless it has been determined that all attribute names are unique.- Parameters:
name- the attribute nametype- the attribute typevalue- the attribute valuespecified-trueif the attribute was specified in the instance document
-
addAttribute
public void addAttribute(QName name, String type, String value, String nonNormalizedValue, boolean specified) Adds an attribute together with its non-normalized (plain) value.This variant stores both the normalized
valueand the originalnonNormalizedValueso that downstream consumers can access the raw attribute text viagetNonNormalizedValue(int).Like other
addAttributeoverloads, this method does not check for duplicate attribute names.- Parameters:
name- the attribute nametype- the attribute type (e.g., "CDATA")value- the normalized attribute valuenonNormalizedValue- the original, non-normalized attribute valuespecified-trueif the attribute was specified in the instance document
-
removeAllAttributes
public void removeAllAttributes()Removes all attributes from the collection. This method also removes all entities associated with the attributes.- Specified by:
removeAllAttributesin interfaceXMLAttributes
-
removeAttributeAt
public void removeAttributeAt(int attrIndex) Removes the attribute at the specified index.Note: This operation shifts the indices of all attributes following the specified index.
- Specified by:
removeAttributeAtin interfaceXMLAttributes- Parameters:
attrIndex- the zero-based attribute index
-
setName
Sets the name of the attribute at the specified index.- Specified by:
setNamein interfaceXMLAttributes- Parameters:
attrIndex- the zero-based attribute indexattrName- the new attribute name
-
getName
Populates the fields of the givenQNamestructure with the values of the attribute name at the specified index.- Specified by:
getNamein interfaceXMLAttributes- Parameters:
attrIndex- the zero-based attribute indexattrName- the attribute name structure to fill in
-
setValue
Sets the value of the attribute at the specified index. This method also overwrites the non-normalized value of the attribute.- Specified by:
setValuein interfaceXMLAttributes- Parameters:
attrIndex- the zero-based attribute indexattrValue- the new attribute value
-
setSpecified
public void setSpecified(int attrIndex, boolean specified) Sets whether an attribute was specified in the instance document.- Specified by:
setSpecifiedin interfaceXMLAttributes- Parameters:
attrIndex- the zero-based attribute indexspecified-trueif the attribute is specified in the instance document
-
isSpecified
public boolean isSpecified(int attrIndex) Returns whether the attribute at the specified index was specified in the instance document.- Specified by:
isSpecifiedin interfaceAttributes2- Parameters:
attrIndex- the zero-based attribute index- Returns:
trueif specified,falseotherwise
-
getLength
public int getLength()Returns the number of attributes in the list.Once you know the number of attributes, you can iterate through the list.
- Specified by:
getLengthin interfaceAttributes- Returns:
- the number of attributes in the list
-
getType
Looks up an attribute's type by index.The attribute type is one of the strings "CDATA", "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES", or "NOTATION" (always in upper case).
If the parser has not read a declaration for the attribute, or if it does not report attribute types, it must return "CDATA" as stated in the XML 1.0 Recommendation (clause 3.3.3, "Attribute-Value Normalization").
- Specified by:
getTypein interfaceAttributes- Parameters:
index- the zero-based attribute index- Returns:
- the attribute's type as a string, or
nullif out of range - See Also:
-
getType
Looks up an attribute's type by XML 1.0 qualified name.See
getType(int)for a description of possible types.- Specified by:
getTypein interfaceAttributes- Parameters:
qname- the XML 1.0 qualified name- Returns:
- the attribute type as a string, or
nullif not found
-
getValue
Looks up an attribute's value by index.If the attribute value is a list of tokens (IDREFS, ENTITIES, or NMTOKENS), tokens are concatenated into a single string separated by a single space.
- Specified by:
getValuein interfaceAttributes- Parameters:
index- the zero-based attribute index- Returns:
- the attribute's value as a string, or
nullif out of range - See Also:
-
getValue
Looks up an attribute's value by XML 1.0 qualified name.See
getValue(int)for a description of possible values.- Specified by:
getValuein interfaceAttributes- Parameters:
qname- the XML 1.0 qualified name- Returns:
- the attribute value as a string, or
nullif not found
-
getNameRawName
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.Returns the raw (prefixed) name of the attribute at the given index. This is a convenience shortcut equivalent to
getName(index).getRawname()with bounds checking.- Parameters:
index- the zero-based attribute index- Returns:
- the raw name of the indexed attribute, or
nullif out of range - See Also:
-
getName
Returns the fullQNamestructure of the attribute at the specified index.- Specified by:
getNamein interfaceXMLAttributes- Parameters:
index- the zero-based attribute index- Returns:
- the attribute's full
QName
-
getIndex
Looks up the index of an attribute by XML 1.0 qualified name.- Specified by:
getIndexin interfaceAttributes- Parameters:
qName- the qualified (prefixed) name- Returns:
- the attribute index, or
-1if it does not appear in the list
-
getIndex
Looks up the index of an attribute by Namespace name.- Specified by:
getIndexin interfaceAttributes- Parameters:
uri- the Namespace URI, ornullif nonelocalPart- the attribute's local name- Returns:
- the attribute index, or
-1if it does not appear in the list
-
getLocalName
Looks up an attribute's local name by index.- Specified by:
getLocalNamein interfaceAttributes- Parameters:
index- the zero-based attribute index- Returns:
- the local name, empty string if namespaces are disabled, or
nullif out of range - See Also:
-
getQName
Looks up an attribute's XML 1.0 qualified name by index.- Specified by:
getQNamein interfaceAttributes- Parameters:
index- the zero-based attribute index- Returns:
- the qualified name, empty string if none available, or
nullif out of range - See Also:
-
getType
Looks up an attribute's type by Namespace name.See
getType(int)for a description of possible types.- Specified by:
getTypein interfaceAttributes- Parameters:
uri- the Namespace URI, ornullif nonelocalName- the local name of the attribute- Returns:
- the attribute type, or
nullif not found
-
getURI
Looks up an attribute's Namespace URI by index.- Specified by:
getURIin interfaceAttributes- Parameters:
index- the zero-based attribute index- Returns:
- the Namespace URI, or
nullif out of range - See Also:
-
getValue
Looks up an attribute's value by Namespace name.See
getValue(int)for a description of possible values.- Specified by:
getValuein interfaceAttributes- Parameters:
uri- the Namespace URI, ornullif nonelocalName- the local name of the attribute- Returns:
- the attribute value, or
nullif not found
-
getNonNormalizedValue
Returns the non-normalized value of the attribute at the specified index. If no non-normalized value is set, this method returns the same value as theAttributes.getValue(int)method.- Specified by:
getNonNormalizedValuein interfaceXMLAttributes- Parameters:
index- the zero-based index of the attribute- Returns:
- the non-normalized value of the attribute at the specified index
-
isDeclared
public boolean isDeclared(int index) - Specified by:
isDeclaredin interfaceAttributes2
-
isDeclared
- Specified by:
isDeclaredin interfaceAttributes2
-
isDeclared
- Specified by:
isDeclaredin interfaceAttributes2
-
isSpecified
- Specified by:
isSpecifiedin interfaceAttributes2
-
isSpecified
- Specified by:
isSpecifiedin interfaceAttributes2
-
getAttributes
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.- Returns:
- the internal attributes
ArrayListto allow performance optimizations
-