The matching rules described earlier in this section match two tags on the basis of their attribute values. There may be times when tags can’t be matched in this way. The J2EE deployment descriptors, for example, do not typically use attributes. This means the matching rules will cause too many tag matches because there are no attribute values to distinguish the tags.

In this case, it may be necessary to “manufacture” an attribute. The J2EE deployment descriptors provide such an attribute, named id. The id attribute is designed to be used for purposes such as these, where tags need to be matched up at a lexical level.

The id tag may be used to hold the value of an embedded value that is known to be unique, as in this example:

<session>
  <ejb-name>Account</ejb-name>
  ...
</session>

<session>
  <ejb-name>Payroll</ejb-name>
  ...
</session>

Here all of the <session> tags are distinguished by the value of their <ejb-name> child tag, but that’s no help to the XML combination rules. In this case, an id attribute must be added to help match up tags:

<session id="Account">
  <ejb-name>Account</ejb-name>
  ...
</session>

<session id="Payroll">
  <ejb-name>Payroll</ejb-name>
  ...
</session>
 
loading table of contents...