I have a piece of code where I want to set a variable from an XML attribute only if that attribute is defined, otherwise do nothing.

Compare the following xml snippets:
<component name="gun" size="0">
vs.
<component name="armor">

In the example above, the "gun" has set the size and the "armor" has not.

How can I check whether an XML item (such as the two components above) has set a particular attribute (such as size)?