| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Objectnu.xom.Node
nu.xom.Attribute
This class represents an attribute such as
type="empty"
or
xlink:href="http://www.example.com"
.
Attributes that declare namespaces such as
xmlns="http://www.w3.org/TR/1999/xhtml"
or xmlns:xlink="http://www.w3.org/TR/1999/xlink"
are stored separately on the elements where they
appear. They are never represented as Attribute
objects.
Nested Class Summary | |
static class | Attribute.Type
Uses the type-safe enumeration design pattern to represent attribute types, as specified by XML DTDs. |
Constructor Summary | |
Attribute(Attribute attribute)
Creates a copy of the specified attribute. | |
Attribute(String localName,
String value)
Creates a new attribute in no namespace with the specified name and value and undeclared type. | |
Attribute(String localName,
String value,
Attribute.Type type)
Creates a new attribute in no namespace with the specified name, value, and type. | |
Attribute(String name,
String URI,
String value)
Creates a new attribute in the specified namespace with the specified name and value and undeclared type. | |
Attribute(String name,
String URI,
String value,
Attribute.Type type)
Creates a new attribute in the specified namespace with the specified name, value, and type. |
Method Summary | |
Node | copy()
Creates a deep copy of this attribute that is not attached to an element. |
Node | getChild(int position)
Throws IndexOutOfBoundsException
because attributes do not have children. |
int | getChildCount()
Returns 0 because attributes do not have children. |
String | getLocalName()
Returns the local name of this attribute, not including the prefix. |
String | getNamespacePrefix()
Returns the prefix of this attribute, or the empty string if this attribute is not in a namespace. |
String | getNamespaceURI()
Returns the namespace URI of this attribute, or the empty string if this attribute is not in a namespace. |
String | getQualifiedName()
Returns the qualified name of this attribute, including the prefix if this attribute is in a namespace. |
Attribute.Type | getType()
Returns the DTD type of this attribute. |
String | getValue()
Returns the attribute value. |
void | setLocalName(String localName)
Sets the local name of the attribute. |
void | setNamespace(String prefix,
String URI)
Sets the attribute's namespace prefix and URI. |
void | setType(Attribute.Type type)
Sets the type of this attribute to one of the ten DTD types or Type.UNDECLARED . |
void | setValue(String value)
Sets the attribute's value to the specified string, replacing any previous value. |
String | toString()
Returns a string representation of the attribute suitable for debugging and diagnosis. |
String | toXML()
Returns a string representation of the attribute that is a well-formed XML attribute. |
Methods inherited from class nu.xom.Node |
detach, equals, getBaseURI, getDocument, getParent, hashCode |
Methods inherited from class Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public Attribute(String localName,
String value)
Creates a new attribute in no namespace with the specified name and value and undeclared type.
localName
- the unprefixed attribute namevalue
- the attribute value
IllegalNameException
- if the local name is not
a namespace well-formed, non-colonized name
IllegalDataException
- if the value contains characters
which are not legal in XML such as vertical tab or a null.
Characters such as " and & are legal, but will be
automatically escaped when the attribute is serialized.
public Attribute(String localName,
String value,
Attribute.Type type)
Creates a new attribute in no namespace with the specified name, value, and type.
localName
- the unprefixed attribute namevalue
- the attribute valuetype
- the attribute type
IllegalNameException
- if the local name is
not a namespace well-formed non-colonized name
IllegalDataException
- if the value contains
characters which are not legal in
XML such as vertical tab or a null. Note that
characters such as " and & are legal,
but will be automatically escaped when the
attribute is serialized.
public Attribute(String name,
String URI,
String value)
Creates a new attribute in the specified namespace with the specified name and value and undeclared type.
name
- the prefixed attribute nameURI
- the namespace URIvalue
- the attribute value
IllegalNameException
- if the name is not a namespace
well-formed prefixed name
IllegalDataException
- if the value contains characters
which are not legal in XML such as vertical tab or a null.
Note that characters such as " and & are legal, but will
be automatically escaped when the attribute is serialized.
MalformedURIException
- if URI
is not
an RFC2396 URI reference
public Attribute(String name,
String URI,
String value,
Attribute.Type type)
Creates a new attribute in the specified namespace with the specified name, value, and type.
name
- the prefixed attribute nameURI
- the namespace URIvalue
- the attribute valuetype
- the attribute type
IllegalNameException
- if the name is not a namespace
well-formed prefixed name
IllegalDataException
- if the value contains
characters which are not legal in XML such as
vertical tab or a null. Note that characters such as
" and & are legal, but will be automatically escaped
when the attribute is serialized.
MalformedURIException
- if URI
is not
an RFC2396 absolute URI reference
public Attribute(Attribute attribute)
Creates a copy of the specified attribute.
attribute
- the attribute to copyMethod Detail |
public final Attribute.Type getType()
Returns the DTD type of this attribute.
If this attribute does not have a type, then
Type.UNDECLARED
is returned.
public void setType(Attribute.Type type)
Sets the type of this attribute to one of the ten
DTD types or Type.UNDECLARED
.
type
- the DTD type of this attribute
public final String getValue()
Returns the attribute value. If the attribute was originally created by a parser, it will have been normalized according to its type. However, attributes created in memory are not normalized.
getValue
in class Node
public void setValue(String value)
Sets the attribute's value to the specified string, replacing any previous value. The value is not normalized automatically.
value
- the value assigned to the attribute
IllegalDataException
- if the value contains characters
which are not legal in XML such as vertical tab or a null.
Characters such as " and & are legal, but will be
automatically escaped when the attribute is serialized.
MalformedURIException
- if this is an
xml:base
attribute, and the value is not a
legal IRI
public final String getLocalName()
Returns the local name of this attribute, not including the prefix.
public void setLocalName(String localName)
Sets the local name of the attribute.
localName
- the new local name
IllegalNameException
- if localName
is not a namespace well-formed, non-colonized name
public final String getQualifiedName()
Returns the qualified name of this attribute, including the prefix if this attribute is in a namespace.
public final String getNamespaceURI()
Returns the namespace URI of this attribute, or the empty string if this attribute is not in a namespace.
public final String getNamespacePrefix()
Returns the prefix of this attribute, or the empty string if this attribute is not in a namespace.
public void setNamespace(String prefix,
String URI)
Sets the attribute's namespace prefix and URI. Because attributes must be prefixed in order to have a namespace URI (and vice versa) this must be done simultaneously.
prefix
- the new namespace prefixURI
- the new namespace URI
MalformedURIException
- if URI
is
not an RFC2396 URI reference
IllegalNameException
- if
xmlns
NamespaceConflictException
- if
xml
and the namespace URI is
not http://www.w3.org/XML/1998/namespace
public final Node getChild(int position)
Throws IndexOutOfBoundsException
because attributes do not have children.
getChild
in class Node
position
- the child to return
IndexOutOfBoundsException
- because attributes do
not have children
public final int getChildCount()
Returns 0 because attributes do not have children.
getChildCount
in class Node
public Node copy()
Creates a deep copy of this attribute that is not attached to an element.
copy
in class Node
public final String toXML()
Returns a string representation of the attribute that is a well-formed XML attribute.
toXML
in class Node
public final String toString()
Returns a string representation of the attribute suitable for debugging and diagnosis. However, this is not necessarily a well-formed XML attribute.
Object.toString()
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |