Attribute Class Reference

Elements can have attributes, which are name="value" pairs that appear within the element start tag in an XML document; this class represents the in-memory representation of one of those attributes and can be used to examine or modify the name or value. More...

#include <Xml.h>

List of all members.

Public Member Functions

 Attribute ()
 Default constructor creates a null Attribute handle.
 Attribute (const String &name, const String &value)
 Create a new orphan Attribute, that is, an Attribute that is not owned by any Xml Element.
 Attribute (const Attribute &src)
 Copy constructor is shallow; that is, this handle will refer to the same attribute as the source.
Attributeoperator= (const Attribute &src)
 Copy assignment is shallow; the handle is first cleared and then will refer to the same attribute as the source.
 ~Attribute ()
 Destructor will delete the referenced attribute if this handle is its owner, otherwise it will be left alone.
bool isValid () const
 Is this handle currently holding an attribute?
const StringgetName () const
 If this is a valid attribute handle, get the name of the attribute.
const StringgetValue () const
 If this is a valid attribute handle, get the value of the attribute as a String, not including the quotes.
AttributesetName (const String &name)
 If this is a valid attribute handle, change its name.
AttributesetValue (const String &value)
 If this is a valid attribute handle, change its value to the given String which should not be quoted.
void clear ()
 Clear this attribute handle; if the handle is the attribute's owner (that is, it isn't part of any element) then the attribute will be deleted, otherwise it is left unchanged.
void writeToString (String &out) const
 Serialize this attribute to the given String.
bool operator== (const Attribute &attr) const
 Comparison operators return true if the same attribute is being referenced or both handles are empty.
bool operator!= (const Attribute &attr) const

Friends

class Xml::attribute_iterator
class Xml::Element

Detailed Description

Elements can have attributes, which are name="value" pairs that appear within the element start tag in an XML document; this class represents the in-memory representation of one of those attributes and can be used to examine or modify the name or value.

Attribute names within an element tag are unique.


Constructor & Destructor Documentation

Attribute (  )  [inline]

Default constructor creates a null Attribute handle.

Attribute ( const String name,
const String value 
)

Create a new orphan Attribute, that is, an Attribute that is not owned by any Xml Element.

Attribute ( const Attribute src  )  [inline]

Copy constructor is shallow; that is, this handle will refer to the same attribute as the source.

Note that this handle will provide write access to the underlying attribute, even if the source was const.

~Attribute (  )  [inline]

Destructor will delete the referenced attribute if this handle is its owner, otherwise it will be left alone.


Member Function Documentation

void clear (  ) 

Clear this attribute handle; if the handle is the attribute's owner (that is, it isn't part of any element) then the attribute will be deleted, otherwise it is left unchanged.

const String& getName (  )  const

If this is a valid attribute handle, get the name of the attribute.

const String& getValue (  )  const

If this is a valid attribute handle, get the value of the attribute as a String, not including the quotes.

Referenced by Element::getOptionalAttributeValue(), and Element::getOptionalAttributeValueAs().

bool isValid (  )  const [inline]

Is this handle currently holding an attribute?

Referenced by Element::getOptionalAttributeValue(), and Element::getOptionalAttributeValueAs().

bool operator!= ( const Attribute attr  )  const [inline]
Attribute& operator= ( const Attribute src  )  [inline]

Copy assignment is shallow; the handle is first cleared and then will refer to the same attribute as the source.

Note that this handle will provide write access to the underlying attribute even if the source handle was const.

See also:
clear()
bool operator== ( const Attribute attr  )  const [inline]

Comparison operators return true if the same attribute is being referenced or both handles are empty.

Note that two different attributes with the same properties will not test equal by this criterion.

Attribute& setName ( const String name  ) 

If this is a valid attribute handle, change its name.

Returns:
A reference to this attribute that now has the new name.
Attribute& setValue ( const String value  ) 

If this is a valid attribute handle, change its value to the given String which should not be quoted.

Returns:
A reference to this attribute that now has the new value.
void writeToString ( String out  )  const

Serialize this attribute to the given String.

The output will be as it would appear in an XML file, i.e. name="value" or name='value' with special characters output as suitable entities. If you don't want it that way, use getName() and getValue() instead which return the raw strings.


Friends And Related Function Documentation

friend class Xml::attribute_iterator [friend]
friend class Xml::Element [friend]

The documentation for this class was generated from the following file:

Generated on Thu Aug 12 16:38:33 2010 for SimTKcore by  doxygen 1.6.1