org.jsoup.nodes
Class Attributes

java.lang.Object
  extended by org.jsoup.nodes.Attributes
All Implemented Interfaces:
Cloneable, Iterable<Attribute>

public class Attributes
extends Object
implements Iterable<Attribute>, Cloneable

The attributes of an Element.

Attributes are treated as a map: there can be only one value associated with an attribute key.

Attribute key and value comparisons are done case insensitively, and keys are normalised to lower-case.

Author:
Jonathan Hedley, jonathan@hedley.net

Field Summary
protected static String dataPrefix
           
 
Constructor Summary
Attributes()
           
 
Method Summary
 void addAll(Attributes incoming)
          Add all the attributes from the incoming set to this set.
 List<Attribute> asList()
          Get the attributes as a List, for iteration.
 Attributes clone()
           
 Map<String,String> dataset()
          Retrieves a filtered view of attributes that are HTML5 custom data attributes; that is, attributes with keys starting with data-.
 boolean equals(Object o)
           
 String get(String key)
          Get an attribute value by key.
 int hashCode()
           
 boolean hasKey(String key)
          Tests if these attributes contain an attribute with this key.
 String html()
          Get the HTML representation of these attributes.
 Iterator<Attribute> iterator()
           
 void put(Attribute attribute)
          Set a new attribute, or replace an existing one by key.
 void put(String key, String value)
          Set a new attribute, or replace an existing one by key.
 void remove(String key)
          Remove an attribute by key.
 int size()
          Get the number of attributes in this set.
 String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

dataPrefix

protected static final String dataPrefix
See Also:
Constant Field Values
Constructor Detail

Attributes

public Attributes()
Method Detail

get

public String get(String key)
Get an attribute value by key.

Parameters:
key - the attribute key
Returns:
the attribute value if set; or empty string if not set.
See Also:
hasKey(String)

put

public void put(String key,
                String value)
Set a new attribute, or replace an existing one by key.

Parameters:
key - attribute key
value - attribute value

put

public void put(Attribute attribute)
Set a new attribute, or replace an existing one by key.

Parameters:
attribute - attribute

remove

public void remove(String key)
Remove an attribute by key.

Parameters:
key - attribute key to remove

hasKey

public boolean hasKey(String key)
Tests if these attributes contain an attribute with this key.

Parameters:
key - key to check for
Returns:
true if key exists, false otherwise

size

public int size()
Get the number of attributes in this set.

Returns:
size

addAll

public void addAll(Attributes incoming)
Add all the attributes from the incoming set to this set.

Parameters:
incoming - attributes to add to these attributes.

iterator

public Iterator<Attribute> iterator()
Specified by:
iterator in interface Iterable<Attribute>

asList

public List<Attribute> asList()
Get the attributes as a List, for iteration. Do not modify the keys of the attributes via this view, as changes to keys will not be recognised in the containing set.

Returns:
an view of the attributes as a List.

dataset

public Map<String,String> dataset()
Retrieves a filtered view of attributes that are HTML5 custom data attributes; that is, attributes with keys starting with data-.

Returns:
map of custom data attributes.

html

public String html()
Get the HTML representation of these attributes.

Returns:
HTML

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

clone

public Attributes clone()
Overrides:
clone in class Object


Copyright © 2009-2012 Jonathan Hedley. All Rights Reserved.