Swarms don't attack, they just deal damage
Swarm Attack: Creatures with the swarm subtype don't make standard melee attacks. Instead, they deal automatic damage to any creature whose space they occupy at the end of their move, with no attack roll needed. Swarm attacks are not subject to a miss chance for concealment or cover. A swarm's statistics block has "swarm" in the Melee entry, with no attack bonus given.
Your examples seem to deal with effects that do something to a creature that attacks the user. However, swarms do not make melee attacks. Thus we need to analyze, case-by-case, what "attacking" means (whether it's the Pathfinder definition about making attack rolls, the Pathfinder definition akin to what ends invisibility, or the standard dictionary definition).
(Let it be said that I think this is a situation where the rules get really messy, and we could argue all day and night about what "attack" means. For example, some might argue that a swarm does make attacks because the ability is named "Swarm Attack". I would counter that the rules, which in my opinion trump names, state that swarms don't make "standard melee attacks". If it doesn't have an attack roll, it's not a proper attack. But moving on...)
Targeting requires choosing
While the game never(*) explicitly explains what "target" and "targeting" mean and how exactly they work, the Magic chapter in CRB gives us this:
Target or Targets: Some spells have a target or targets. You cast these spells on creatures or objects, as defined by the spell itself. You must be able to see or touch the target, and you must specifically choose that target. You do not have to select your target until you finish casting the spell.
This gives me the impression that in order to "target" something, you must actively and specifically choose that exact target. Whether it's a melee attack, a ranged attack, or a spell, if it requires a target, you must choose the target.
Let's look at your examples.
Fire Elemental's Burn
Burn (Ex) A creature with the burn special attack deals fire damage in addition to damage dealt on a successful hit in melee. Those affected by the burn ability must also succeed on a Reflex save (...) Creatures that hit a burning creature with natural weapons or unarmed attacks take fire damage as though hit by the burning creature and must make a Reflex save to avoid catching on fire.
The Burn ability doesn't require the elemental to choose a creature that hit it with a natural weapon or unarmed strike. Because no choice is involved, it's not a "target" effect.
Would a swarm take damage from the Burn ability? No, because the swarm didn't attack with a natural weapon or an unarmed strike. (In 99% of cases, anyway; if you can find a swarm that attacks with a natural weapon then more power to you!)
Fire Shield
Target you
Any creature striking you with its body or a handheld weapon deals normal damage, but at the same time the attacker takes 1d6 points of damage + 1 point per caster level (maximum +15). (...)
Once again, the spell doesn't ask you to choose the attacker, so it is not a "target" effect.
Would a swarm take damage from fire shield? Yes, because unlike the Burn ability, fire shield doesn't mention attacking at all. Instead, fire shield activates when a creture "strikes you with its body". Swarms usually do their swarm damage by exactly that: they surround you and use their bodies to cause damage.
Thorn Body
Target you
Any creature striking you with a melee weapon, an unarmed strike, or a natural weapon takes 1d6 points of piercing damage +1 point per caster level (maximum +15).
The spell doesn't ask the caster to choose the attack; no choice involved, not a "target" effect.
Would a swarm take damage from thorn body? No, because it doesn't attack with a melee weapon, an unarmed strike, or a natural weapon.
(*) It is difficult to prove a negative. I searched, with ctrl+f, CRB's Combat chapter about definitions of "target", and found no paragraph about it.