public class XMLAttributes extends Object
This class of objects is defined by libSBML only and has no direct equivalent in terms of SBML components. This class is not prescribed by the SBML specifications, although it is used to implement features defined in SBML.
In libSBML's XML interface layer, attributes on an element are stored as a
list of values kept in an XMLAttributes
object. XMLAttributes
has methods
for adding and removing individual attributes as well as performing other
actions on the list of attributes. Classes in libSBML that represent nodes
in an XML document (i.e., XMLNode
and its parent class, XMLToken
) use
XMLAttributes
objects to manage attributes on XML elements.
Attributes on an XML element can be written in one of two forms:
name='value'
prefix:name='value'
An attribute in XML must always have a value, and the value must always be
a quoted string i.e., it is always name='value'
and not
name=value
. An empty value is represented simply as an
empty string i.e., name=''
.
In cases when a prefix
is provided with an attribute name,
general XML validity rules require that the prefix is an XML namespace
prefix that has been declared somewhere else (possibly as an another
attribute on the same element). However, the XMLAttributes
class does
not test for the proper existence or declaration of XML
namespaces&mdashcallers must arrange to do this themselves in some other
way. This class only provides facilities for tracking and manipulating
attributes and their prefix/URI/name/value components.
XMLTriple
,
XMLNode
,
XMLToken
XMLAttributes
provides operations that can
manipulate attributes based on a numerical index, XML attributes are in
fact unordered when they appear in files and data streams. The
XMLAttributes
class provides some list-like facilities, but it is only for
the convenience of callers. (For example, it permits callers to loop
across all attributes more easily.) Users should keep in mind that the
order in which attributes are stored in XMLAttributes
objects has no real
impact on the order in which the attributes are read or written from an
XML file or data stream.
Constructor and Description |
---|
XMLAttributes()
Creates a new, empty
XMLAttributes object. |
XMLAttributes(XMLAttributes orig)
Copy constructor creates a copy of this
XMLAttributes object. |
Modifier and Type | Method and Description |
---|---|
int |
add(String name,
String value)
Adds an attribute to this list of attributes.
|
int |
add(String name,
String value,
String namespaceURI)
Adds an attribute to this list of attributes.
|
int |
add(String name,
String value,
String namespaceURI,
String prefix)
Adds an attribute to this list of attributes.
|
int |
add(XMLTriple triple,
String value)
Adds an attribute to this list of attributes.
|
int |
clear()
Removes all attributes in this
XMLAttributes object. |
XMLAttributes |
cloneObject()
Creates and returns a deep copy of this
XMLAttributes object. |
void |
delete()
Explicitly deletes the underlying native object.
|
boolean |
equals(Object sb)
Equality comparison method for XMLAttributes.
|
int |
getIndex(String name)
Returns the index of an attribute having a given name.
|
int |
getIndex(String name,
String uri)
Returns the index of the attribute having a given name and XML namespace
URI.
|
int |
getIndex(XMLTriple triple)
Returns the index of the attribute defined by the given
XMLTriple object. |
int |
getLength()
Returns the number of attributes in this list of attributes.
|
String |
getName(int index)
Returns the name of the nth attribute in this list of
attributes.
|
int |
getNumAttributes()
Returns the number of attributes in this list of attributes.
|
String |
getPrefix(int index)
Returns the namespace prefix of the nth attribute in this
attribute set.
|
String |
getPrefixedName(int index)
Returns the prefix name of the nth attribute in this attribute
set.
|
String |
getURI(int index)
Returns the XML namespace URI of the nth attribute in this
attribute set.
|
String |
getValue(int index)
Returns the value of the nth attribute in this list of attributes.
|
String |
getValue(String name)
Returns a named attribute's value.
|
String |
getValue(String name,
String uri)
Returns a named attribute's value.
|
String |
getValue(XMLTriple triple)
Return the value of an attribute described by a given
XMLTriple object. |
boolean |
hasAttribute(int index)
Returns
true if an attribute exists at a given index. |
boolean |
hasAttribute(String name)
Returns
true if an attribute with a given name and namespace URI
exists. |
boolean |
hasAttribute(String name,
String uri)
Returns
true if an attribute with a given name and namespace URI
exists. |
boolean |
hasAttribute(XMLTriple triple)
Returns
true if an attribute with the given properties exists. |
int |
hashCode()
Returns a hashcode for this XMLAttributes object.
|
boolean |
isEmpty()
Returns
true if this list of attributes is empty. |
int |
remove(int n)
Removes the nth attribute from this list of attributes.
|
int |
remove(String name)
Removes a named attribute from this list of attributes.
|
int |
remove(String name,
String uri)
Removes a named attribute from this list of attributes.
|
int |
remove(XMLTriple triple)
Removes a specific attribute from this list of attributes.
|
public XMLAttributes() throws XMLConstructorException
XMLAttributes
object.XMLConstructorException
public XMLAttributes(XMLAttributes orig) throws XMLConstructorException
XMLAttributes
object.
orig
the XMLAttributes
object to copy.
XMLConstructorException
public void delete()
In general, application software will not need to call this method directly. The Java language binding for libSBML is implemented as a language wrapper that provides a Java interface to libSBML's underlying C++/C code. Some of the Java methods return objects that are linked to objects created not by Java code, but by C++ code. The Java objects wrapped around them will be deleted when the garbage collector invokes the corresponding C++ finalize()
methods for the objects. The finalize()
methods in turn call the XMLAttributes.delete()
method on the libSBML object.
This method is exposed in case calling programs want to ensure that the underlying object is freed immediately, and not at some arbitrary time determined by the Java garbage collector. In normal usage, callers do not need to invoke XMLAttributes.delete()
themselves.
public boolean equals(Object sb)
Because the Java methods for libSBML are actually wrappers around code
implemented in C++ and C, certain operations will not behave as
expected. Equality comparison is one such case. An instance of a
libSBML object class is actually a proxy object
wrapping the real underlying C/C++ object. The normal ==
equality operator in Java will only compare the Java proxy objects,
not the underlying native object. The result is almost never what you
want in practical situations. Unfortunately, Java does not provide a
way to override ==
.
The alternative that must be followed is to use the
equals()
method. The equals
method on this
class overrides the default java.lang.Object one, and performs an
intelligent comparison of instances of objects of this class. The
result is an assessment of whether two libSBML Java objects are truly
the same underlying native-code objects.
The use of this method in practice is the same as the use of any other
Java equals
method. For example,
a.equals(
b)
returns
true
if a and b are references to the
same underlying object.
public int hashCode()
public XMLAttributes cloneObject()
XMLAttributes
object.
XMLAttributes
object.public int add(String name, String value, String namespaceURI, String prefix)
Some explanations are in order about the behavior of XMLAttributes
with
respect to namespace prefixes and namespace URIs. XMLAttributes
does
not verify the consistency of different uses of an XML namespace and the
prefix used to refer to it in a given context. It cannot, because the
prefix used for a given XML namespace in an XML document may intentionally
be different on different elements in the document. Consequently, callers
need to manage their own prefix-to-namespace mappings, and need to ensure
that the desired prefix is used in any given context.
When called with attribute names, prefixes and namespace URIs,
XMLAttributes
pays attention to the namespace URIs and not the prefixes: a
match is established by a combination of attribute name and namespace URI,
and if on different occasions a different prefix is used for the same
name/namespace combination, the prefix associated with the namespace on
that attribute is overwritten.
Some examples will hopefully clarify this. Here are the results of a
sequence of calls to the XMLAttributes
add
methods with
different argument combinations. First, we create the object and add
one attribute:
{.cpp}The above adds an attribute namedXMLAttributes
att = newXMLAttributes
() att->add('myattribute', '1', 'myuri')
myattribute
in the namespace
myuri
, and with the attribute value 1
. No
namespace prefix is associated with the attribute (but the attribute is
recorded to exist in the namespace myuri
). If
this attribute object were written out in XML, it would look like the
following (and note that, since no namespace prefix was assigned, none
is written out):
myattribute='1'
Continuing with this series of examples, suppose we invoke the
add
method again as follows:
{.cpp} att->add('myattribute', '2')The above adds a new attribute also named
myattribute
,
but in a different XML namespace: it is placed in the namespace with no
URI, which is to say, the default XML namespace. Both attributes coexist
on this XMLAttributes
object both can be independently retrieved.
{.cpp} att->add('myattribute', '3')The code above now replaces the value of the attribute
myattribute
that resides in the default namespace. The
attribute in the namespace myuri
remains untouched.
{.cpp} att->add('myattribute', '4', 'myuri')The code above replaces the value of the attribute
myattribute
that resides in the myuri
namespace.
The attribute in the default namespace remains untouched.
{.cpp} att->add('myattribute', '5', 'myuri', 'foo')The code above replaces the value of the attribute
myattribute
that resides in the myuri
namespace.
It also now assigns a namespace prefix, foo
, to the attribute.
The attribute myattribute
in the default namespace remains
untouched. If this XMLAttributes
object were written out in XML, it would
look like the following:
myattribute='3' foo:myattribute='5'
add
method as follows:
{.cpp} att->add('myattribute', '6', 'myuri', 'bar')The code above replaces the value of the attribute
myattribute
that resides in the myuri
namespace.
It also assigns a different prefix to the attribute. The namespace of
the attribute remains myuri
.
{.cpp} att->add('myattribute', '7', '', 'foo')
The code above replaces the value of the attribute
myattribute
that resides in the default namespace. It also
now assigns a namespace prefix, foo
, to that attribute. If
this XMLAttributes
object were written out in XML, it would look like the
following:
bar:myattribute='6' foo:myattribute='7'
name
- a string, the unprefixed name of the attribute.value
- a string, the value of the attribute.namespaceURI
- a string, the namespace URI of the attribute.prefix
- a string, a prefix for the XML namespace.
LIBSBML_OPERATION_SUCCESS
LIBSBML_INVALID_OBJECT
&ndash this value is returned if any of the arguments are null.
To
set an empty prefix
and/or name
value, use an empty string rather
than null.
XMLAttributes.add(XMLTriple triple, String value)
,
XMLAttributes.getIndex(String name, String uri)
,
XMLAttributes.getIndex(XMLTriple triple)
,
XMLAttributes.hasAttribute(String name, String uri)
,
XMLAttributes.hasAttribute(XMLTriple triple)
XMLAttributes
object, then
the previous value of that attribute will be replaced with the new value
provided to this method.
public int add(String name, String value, String namespaceURI)
Some explanations are in order about the behavior of XMLAttributes
with
respect to namespace prefixes and namespace URIs. XMLAttributes
does
not verify the consistency of different uses of an XML namespace and the
prefix used to refer to it in a given context. It cannot, because the
prefix used for a given XML namespace in an XML document may intentionally
be different on different elements in the document. Consequently, callers
need to manage their own prefix-to-namespace mappings, and need to ensure
that the desired prefix is used in any given context.
When called with attribute names, prefixes and namespace URIs,
XMLAttributes
pays attention to the namespace URIs and not the prefixes: a
match is established by a combination of attribute name and namespace URI,
and if on different occasions a different prefix is used for the same
name/namespace combination, the prefix associated with the namespace on
that attribute is overwritten.
Some examples will hopefully clarify this. Here are the results of a
sequence of calls to the XMLAttributes
add
methods with
different argument combinations. First, we create the object and add
one attribute:
{.cpp}The above adds an attribute namedXMLAttributes
att = newXMLAttributes
() att->add('myattribute', '1', 'myuri')
myattribute
in the namespace
myuri
, and with the attribute value 1
. No
namespace prefix is associated with the attribute (but the attribute is
recorded to exist in the namespace myuri
). If
this attribute object were written out in XML, it would look like the
following (and note that, since no namespace prefix was assigned, none
is written out):
myattribute='1'
Continuing with this series of examples, suppose we invoke the
add
method again as follows:
{.cpp} att->add('myattribute', '2')The above adds a new attribute also named
myattribute
,
but in a different XML namespace: it is placed in the namespace with no
URI, which is to say, the default XML namespace. Both attributes coexist
on this XMLAttributes
object both can be independently retrieved.
{.cpp} att->add('myattribute', '3')The code above now replaces the value of the attribute
myattribute
that resides in the default namespace. The
attribute in the namespace myuri
remains untouched.
{.cpp} att->add('myattribute', '4', 'myuri')The code above replaces the value of the attribute
myattribute
that resides in the myuri
namespace.
The attribute in the default namespace remains untouched.
{.cpp} att->add('myattribute', '5', 'myuri', 'foo')The code above replaces the value of the attribute
myattribute
that resides in the myuri
namespace.
It also now assigns a namespace prefix, foo
, to the attribute.
The attribute myattribute
in the default namespace remains
untouched. If this XMLAttributes
object were written out in XML, it would
look like the following:
myattribute='3' foo:myattribute='5'
add
method as follows:
{.cpp} att->add('myattribute', '6', 'myuri', 'bar')The code above replaces the value of the attribute
myattribute
that resides in the myuri
namespace.
It also assigns a different prefix to the attribute. The namespace of
the attribute remains myuri
.
{.cpp} att->add('myattribute', '7', '', 'foo')
The code above replaces the value of the attribute
myattribute
that resides in the default namespace. It also
now assigns a namespace prefix, foo
, to that attribute. If
this XMLAttributes
object were written out in XML, it would look like the
following:
bar:myattribute='6' foo:myattribute='7'
name
- a string, the unprefixed name of the attribute.value
- a string, the value of the attribute.namespaceURI
- a string, the namespace URI of the attribute.prefix
- a string, a prefix for the XML namespace.
LIBSBML_OPERATION_SUCCESS
LIBSBML_INVALID_OBJECT
&ndash this value is returned if any of the arguments are null.
To
set an empty prefix
and/or name
value, use an empty string rather
than null.
XMLAttributes.add(XMLTriple triple, String value)
,
XMLAttributes.getIndex(String name, String uri)
,
XMLAttributes.getIndex(XMLTriple triple)
,
XMLAttributes.hasAttribute(String name, String uri)
,
XMLAttributes.hasAttribute(XMLTriple triple)
XMLAttributes
object, then
the previous value of that attribute will be replaced with the new value
provided to this method.
public int add(String name, String value)
Some explanations are in order about the behavior of XMLAttributes
with
respect to namespace prefixes and namespace URIs. XMLAttributes
does
not verify the consistency of different uses of an XML namespace and the
prefix used to refer to it in a given context. It cannot, because the
prefix used for a given XML namespace in an XML document may intentionally
be different on different elements in the document. Consequently, callers
need to manage their own prefix-to-namespace mappings, and need to ensure
that the desired prefix is used in any given context.
When called with attribute names, prefixes and namespace URIs,
XMLAttributes
pays attention to the namespace URIs and not the prefixes: a
match is established by a combination of attribute name and namespace URI,
and if on different occasions a different prefix is used for the same
name/namespace combination, the prefix associated with the namespace on
that attribute is overwritten.
Some examples will hopefully clarify this. Here are the results of a
sequence of calls to the XMLAttributes
add
methods with
different argument combinations. First, we create the object and add
one attribute:
{.cpp}The above adds an attribute namedXMLAttributes
att = newXMLAttributes
() att->add('myattribute', '1', 'myuri')
myattribute
in the namespace
myuri
, and with the attribute value 1
. No
namespace prefix is associated with the attribute (but the attribute is
recorded to exist in the namespace myuri
). If
this attribute object were written out in XML, it would look like the
following (and note that, since no namespace prefix was assigned, none
is written out):
myattribute='1'
Continuing with this series of examples, suppose we invoke the
add
method again as follows:
{.cpp} att->add('myattribute', '2')The above adds a new attribute also named
myattribute
,
but in a different XML namespace: it is placed in the namespace with no
URI, which is to say, the default XML namespace. Both attributes coexist
on this XMLAttributes
object both can be independently retrieved.
{.cpp} att->add('myattribute', '3')The code above now replaces the value of the attribute
myattribute
that resides in the default namespace. The
attribute in the namespace myuri
remains untouched.
{.cpp} att->add('myattribute', '4', 'myuri')The code above replaces the value of the attribute
myattribute
that resides in the myuri
namespace.
The attribute in the default namespace remains untouched.
{.cpp} att->add('myattribute', '5', 'myuri', 'foo')The code above replaces the value of the attribute
myattribute
that resides in the myuri
namespace.
It also now assigns a namespace prefix, foo
, to the attribute.
The attribute myattribute
in the default namespace remains
untouched. If this XMLAttributes
object were written out in XML, it would
look like the following:
myattribute='3' foo:myattribute='5'
add
method as follows:
{.cpp} att->add('myattribute', '6', 'myuri', 'bar')The code above replaces the value of the attribute
myattribute
that resides in the myuri
namespace.
It also assigns a different prefix to the attribute. The namespace of
the attribute remains myuri
.
{.cpp} att->add('myattribute', '7', '', 'foo')
The code above replaces the value of the attribute
myattribute
that resides in the default namespace. It also
now assigns a namespace prefix, foo
, to that attribute. If
this XMLAttributes
object were written out in XML, it would look like the
following:
bar:myattribute='6' foo:myattribute='7'
name
- a string, the unprefixed name of the attribute.value
- a string, the value of the attribute.namespaceURI
- a string, the namespace URI of the attribute.prefix
- a string, a prefix for the XML namespace.
LIBSBML_OPERATION_SUCCESS
LIBSBML_INVALID_OBJECT
&ndash this value is returned if any of the arguments are null.
To
set an empty prefix
and/or name
value, use an empty string rather
than null.
XMLAttributes.add(XMLTriple triple, String value)
,
XMLAttributes.getIndex(String name, String uri)
,
XMLAttributes.getIndex(XMLTriple triple)
,
XMLAttributes.hasAttribute(String name, String uri)
,
XMLAttributes.hasAttribute(XMLTriple triple)
XMLAttributes
object, then
the previous value of that attribute will be replaced with the new value
provided to this method.
public int add(XMLTriple triple, String value)
Some explanations are in order about the behavior of XMLAttributes
with
respect to namespace prefixes and namespace URIs. XMLAttributes
does
not verify the consistency of different uses of an XML namespace and the
prefix used to refer to it in a given context. It cannot, because the
prefix used for a given XML namespace in an XML document may intentionally
be different on different elements in the document. Consequently, callers
need to manage their own prefix-to-namespace mappings, and need to ensure
that the desired prefix is used in any given context.
When called with attribute names, prefixes and namespace URIs,
XMLAttributes
pays attention to the namespace URIs and not the prefixes: a
match is established by a combination of attribute name and namespace URI,
and if on different occasions a different prefix is used for the same
name/namespace combination, the prefix associated with the namespace on
that attribute is overwritten.
Some examples will hopefully clarify this. Here are the results of a
sequence of calls to the XMLAttributes
add
methods with
different argument combinations. First, we create the object and add
one attribute:
{.cpp}The above adds an attribute namedXMLAttributes
att = newXMLAttributes
() att->add('myattribute', '1', 'myuri')
myattribute
in the namespace
myuri
, and with the attribute value 1
. No
namespace prefix is associated with the attribute (but the attribute is
recorded to exist in the namespace myuri
). If
this attribute object were written out in XML, it would look like the
following (and note that, since no namespace prefix was assigned, none
is written out):
myattribute='1'
Continuing with this series of examples, suppose we invoke the
add
method again as follows:
{.cpp} att->add('myattribute', '2')The above adds a new attribute also named
myattribute
,
but in a different XML namespace: it is placed in the namespace with no
URI, which is to say, the default XML namespace. Both attributes coexist
on this XMLAttributes
object both can be independently retrieved.
{.cpp} att->add('myattribute', '3')The code above now replaces the value of the attribute
myattribute
that resides in the default namespace. The
attribute in the namespace myuri
remains untouched.
{.cpp} att->add('myattribute', '4', 'myuri')The code above replaces the value of the attribute
myattribute
that resides in the myuri
namespace.
The attribute in the default namespace remains untouched.
{.cpp} att->add('myattribute', '5', 'myuri', 'foo')The code above replaces the value of the attribute
myattribute
that resides in the myuri
namespace.
It also now assigns a namespace prefix, foo
, to the attribute.
The attribute myattribute
in the default namespace remains
untouched. If this XMLAttributes
object were written out in XML, it would
look like the following:
myattribute='3' foo:myattribute='5'
add
method as follows:
{.cpp} att->add('myattribute', '6', 'myuri', 'bar')The code above replaces the value of the attribute
myattribute
that resides in the myuri
namespace.
It also assigns a different prefix to the attribute. The namespace of
the attribute remains myuri
.
{.cpp} att->add('myattribute', '7', '', 'foo')
The code above replaces the value of the attribute
myattribute
that resides in the default namespace. It also
now assigns a namespace prefix, foo
, to that attribute. If
this XMLAttributes
object were written out in XML, it would look like the
following:
bar:myattribute='6' foo:myattribute='7'
triple
- an XMLTriple
object describing the attribute to be added.value
- a string, the value of the attribute.
LIBSBML_OPERATION_SUCCESS
LIBSBML_INVALID_OBJECT
&ndash this value is returned if any of the arguments are null.
To
set an empty value for the attribute, use an empty string rather than
null.
XMLAttributes.add(String name, String value, String namespaceURI, String prefix)
,
XMLAttributes.getIndex(String name, String uri)
,
XMLAttributes.getIndex(XMLTriple triple)
,
XMLAttributes.hasAttribute(String name, String uri)
,
XMLAttributes.hasAttribute(XMLTriple triple)
XMLAttributes
object, then
the previous value of that attribute will be replaced with the new value
provided to this method.
public int remove(int n)
n
- an integer the index of the resource to be deleted
The value LIBSBML_INDEX_EXCEEDS_SIZE
is returned if there is no attribute at the
given index n
.
XMLAttributes.getLength()
,
XMLAttributes.remove(XMLTriple triple)
,
XMLAttributes.remove(String name, String uri)
XMLAttributes
provides operations that can
manipulate attributes based on a numerical index, XML attributes are in
fact unordered when they appear in files and data streams. The
XMLAttributes
class provides some list-like facilities, but it is only for
the convenience of callers. (For example, it permits callers to loop
across all attributes more easily.) Users should keep in mind that the
order in which attributes are stored in XMLAttributes
objects has no real
impact on the order in which the attributes are read or written from an
XML file or data stream.
public int remove(String name, String uri)
name
- a string, the unprefixed name of the attribute to be
removed.
uri
- a string, the namespace URI of the attribute to be removed.
The value LIBSBML_INDEX_EXCEEDS_SIZE
is returned if there is no attribute with the
given name
(and uri
if specified).
XMLAttributes.remove(int n)
,
XMLAttributes.remove(XMLTriple triple)
public int remove(String name)
name
- a string, the unprefixed name of the attribute to be
removed.
uri
- a string, the namespace URI of the attribute to be removed.
The value LIBSBML_INDEX_EXCEEDS_SIZE
is returned if there is no attribute with the
given name
(and uri
if specified).
XMLAttributes.remove(int n)
,
XMLAttributes.remove(XMLTriple triple)
public int remove(XMLTriple triple)
triple
- an XMLTriple
describing the attribute to be removed.
The value LIBSBML_INDEX_EXCEEDS_SIZE
is returned if there is no attribute matching
the properties of the given triple
.
XMLAttributes.remove(int n)
,
XMLAttributes.remove(String name, String uri)
public int clear()
XMLAttributes
object.
XMLAttributes.remove(int n)
,
XMLAttributes.remove(XMLTriple triple)
,
XMLAttributes.remove(String name, String uri)
public int getIndex(String name)
name
- a string, the name of the attribute whose index is begin
sought.
-1
if no such attribute is present.
XMLAttributes.hasAttribute(String name, String uri)
,
XMLAttributes.hasAttribute(XMLTriple triple)
name
but different
namespaces, this method will return the first one found. Callers should
use the more specific methods
XMLAttributes.getIndex(String name, String uri)
or XMLAttributes.getIndex(XMLTriple triple)
to find attributes in particular namespaces.
public int getIndex(String name, String uri)
name
- a string, the name of the attribute being sought.uri
- a string, the namespace URI of the attribute being sought.
-1
if no such attribute is present.
XMLAttributes.hasAttribute(String name, String uri)
,
XMLAttributes.hasAttribute(XMLTriple triple)
public int getIndex(XMLTriple triple)
XMLTriple
object.
triple
- an XMLTriple
describing the attribute being sought.
XMLTriple
object, or -1
if no such attribute is present.
XMLAttributes.hasAttribute(String name, String uri)
,
XMLAttributes.hasAttribute(XMLTriple triple)
public int getLength()
XMLAttributes
object.public int getNumAttributes()
This function is merely an alias of XMLAttributes.getLength()
introduced for consistency with other libXML classes.
XMLAttributes
object.public String getName(int index)
index
- an integer, the position of the attribute whose name
is being sought.
XMLAttributes.getLength()
,
XMLAttributes.hasAttribute(int index)
index
is out of range, this method will return an empty
string. Callers should use XMLAttributes.getLength()
to check the number
of attributes contained in this object or XMLAttributes.hasAttribute(int
index)
to test for the existence of an attribute at a given
position.
, Note that although XMLAttributes
provides operations that can
manipulate attributes based on a numerical index, XML attributes are in
fact unordered when they appear in files and data streams. The
XMLAttributes
class provides some list-like facilities, but it is only for
the convenience of callers. (For example, it permits callers to loop
across all attributes more easily.) Users should keep in mind that the
order in which attributes are stored in XMLAttributes
objects has no real
impact on the order in which the attributes are read or written from an
XML file or data stream.
public String getPrefix(int index)
index
- an integer, the position of the attribute whose namespace
prefix is being sought.
XMLAttributes.getLength()
,
XMLAttributes.hasAttribute(int index)
index
is out of range, this method will return an empty
string. Callers should use XMLAttributes.getLength()
to check the number
of attributes contained in this object or XMLAttributes.hasAttribute(int
index)
to test for the existence of an attribute at a given
position.
, Note that although XMLAttributes
provides operations that can
manipulate attributes based on a numerical index, XML attributes are in
fact unordered when they appear in files and data streams. The
XMLAttributes
class provides some list-like facilities, but it is only for
the convenience of callers. (For example, it permits callers to loop
across all attributes more easily.) Users should keep in mind that the
order in which attributes are stored in XMLAttributes
objects has no real
impact on the order in which the attributes are read or written from an
XML file or data stream.
public String getPrefixedName(int index)
index
- an integer, the position of the attribute whose prefixed
name is being sought.
XMLAttributes.getLength()
,
XMLAttributes.hasAttribute(int index)
index
is out of range, this method will return an empty
string. Callers should use XMLAttributes.getLength()
to check the number
of attributes contained in this object or XMLAttributes.hasAttribute(int
index)
to test for the existence of an attribute at a given
position.
, Note that although XMLAttributes
provides operations that can
manipulate attributes based on a numerical index, XML attributes are in
fact unordered when they appear in files and data streams. The
XMLAttributes
class provides some list-like facilities, but it is only for
the convenience of callers. (For example, it permits callers to loop
across all attributes more easily.) Users should keep in mind that the
order in which attributes are stored in XMLAttributes
objects has no real
impact on the order in which the attributes are read or written from an
XML file or data stream.
public String getURI(int index)
index
- an integer, the position of the attribute whose namespace
URI is being sought.
XMLAttributes.getLength()
,
XMLAttributes.hasAttribute(int index)
index
is out of range, this method will return an empty
string. Callers should use XMLAttributes.getLength()
to check the number
of attributes contained in this object or XMLAttributes.hasAttribute(int
index)
to test for the existence of an attribute at a given
position.
, Note that although XMLAttributes
provides operations that can
manipulate attributes based on a numerical index, XML attributes are in
fact unordered when they appear in files and data streams. The
XMLAttributes
class provides some list-like facilities, but it is only for
the convenience of callers. (For example, it permits callers to loop
across all attributes more easily.) Users should keep in mind that the
order in which attributes are stored in XMLAttributes
objects has no real
impact on the order in which the attributes are read or written from an
XML file or data stream.
public String getValue(int index)
index
- an integer, the position of the attribute whose value is
being sought.
XMLAttributes.getLength()
,
XMLAttributes.hasAttribute(int index)
index
is out of range, this method will return an empty
string. Callers should use XMLAttributes.getLength()
to check the number
of attributes contained in this object or XMLAttributes.hasAttribute(int
index)
to test for the existence of an attribute at a given
position.
, Note that although XMLAttributes
provides operations that can
manipulate attributes based on a numerical index, XML attributes are in
fact unordered when they appear in files and data streams. The
XMLAttributes
class provides some list-like facilities, but it is only for
the convenience of callers. (For example, it permits callers to loop
across all attributes more easily.) Users should keep in mind that the
order in which attributes are stored in XMLAttributes
objects has no real
impact on the order in which the attributes are read or written from an
XML file or data stream.
public String getValue(String name)
name
- a string, the unprefixed name of the attribute whose value
is being sought.
XMLAttributes.hasAttribute(String name, String uri)
,
XMLAttributes.hasAttribute(XMLTriple triple)
name
does not exist in
this XMLAttributes
object, this method will return an empty string.
Callers can use
XMLAttributes.hasAttribute(String name, String uri)
to test for an attribute's existence. This method also does not check
the XML namespace of the named attribute. Thus, if there are multiple
attributes with the same local name
but different namespaces, this
method will return the value of the first such attribute found. Callers
should use the more specific methods
XMLAttributes.getIndex(String name, String uri)
or XMLAttributes.getIndex(XMLTriple triple)
to find
attributes in particular namespaces.
public String getValue(String name, String uri)
name
- a string, the name of the attribute whose value is being sought.uri
- a string, the XML namespace URI of the attribute.
XMLAttributes.hasAttribute(String name, String uri)
,
XMLAttributes.hasAttribute(XMLTriple triple)
name
and namespace uri
does
not exist in this XMLAttributes
object, this method will return an empty
string. Callers can use
XMLAttributes.hasAttribute(String name, String uri)
to test for an attribute's existence.
public String getValue(XMLTriple triple)
XMLTriple
object.
triple
- an XMLTriple
describing the attribute whose value is being
sought.
XMLAttributes.hasAttribute(String name, String uri)
,
XMLAttributes.hasAttribute(XMLTriple triple)
triple
does not
exist in this XMLAttributes
object, this method will return an empty
string. Callers can use
XMLAttributes.hasAttribute(String name, String uri)
to test for an attribute's existence.
public boolean hasAttribute(int index)
true
if an attribute exists at a given index.
index
- an integer, the position of the attribute to be tested.
true
if an attribute with the given index exists in this
XMLAttributes
object, false
otherwise.
XMLAttributes
provides operations that can
manipulate attributes based on a numerical index, XML attributes are in
fact unordered when they appear in files and data streams. The
XMLAttributes
class provides some list-like facilities, but it is only for
the convenience of callers. (For example, it permits callers to loop
across all attributes more easily.) Users should keep in mind that the
order in which attributes are stored in XMLAttributes
objects has no real
impact on the order in which the attributes are read or written from an
XML file or data stream.public boolean hasAttribute(String name, String uri)
true
if an attribute with a given name and namespace URI
exists.
name
- a string, the unprefixed name of the attribute.uri
- a string, the XML namespace URI of the attribute.
true
if an attribute with the given local name and XML
namespace URI exists in this XMLAttributes
object, false
otherwise.
XMLAttributes.add(String name, String value, String namespaceURI, String prefix)
,
XMLAttributes.add(XMLTriple triple, String value)
public boolean hasAttribute(String name)
true
if an attribute with a given name and namespace URI
exists.
name
- a string, the unprefixed name of the attribute.uri
- a string, the XML namespace URI of the attribute.
true
if an attribute with the given local name and XML
namespace URI exists in this XMLAttributes
object, false
otherwise.
XMLAttributes.add(String name, String value, String namespaceURI, String prefix)
,
XMLAttributes.add(XMLTriple triple, String value)
public boolean hasAttribute(XMLTriple triple)
true
if an attribute with the given properties exists.
triple
- an XMLTriple
describing the attribute to be tested.
true
if an attribute with the given XML triple exists in this
XMLAttributes
object, false
otherwise.
XMLAttributes.add(String name, String value, String namespaceURI, String prefix)
,
XMLAttributes.add(XMLTriple triple, String value)
public boolean isEmpty()
true
if this list of attributes is empty.
true
if this XMLAttributes
object is empty, false
otherwise.