@Numetalfan welcome to xml programming for TripleA!!
I'm going to assume that you have very little, if any, prior code writing knowledge. If that is true, then congrats Sir! This is an excellent first attempt!
Your first steps are right, by defining what you want, a 'barracks' unit that can only produce infantry units. You added the unit to the unit list, and defined its productionRule. The next is repair, like a factory, this unit should be damageable by SBR:
<cost resource="PUs" quantity="1"/>
<result resourceOrUnit="barracks" quantity="1"/>
Then add the repairRule to the repairFrontier:
And so that countries can buy this unit, it will need to be added to the productionFrontier:
So far so good, now to the barracks attachment:
<!--- Barracks --->
<attachment name="unitAttachment" attachTo="barracks" javaClass="games.strategy.triplea.attachments.UnitAttachment" type="unitType">
<option name="isFactory" value="true"/>
Ok so far. At this point there are two production units, factory and barracks. And both unit can produce all units. So how do we restrict the production of the barracks? We limit where each unit can be produced. In each unitAttachment, artillery, armour, fighter, bomber, transport, battleship, cruiser, destroyer, carrier, submarine and don't forget the aaGun add:
<option name="requiresUnits" value="factory"/>
Because infantry can be produced by both, there doesn't need to be anything added to its unitAttachment.
One last step is to add the option to use requiresUnits:
<property name="Unit Placement Restrictions" value="true" editable="false">
And there you have it. The barracks should now work as designed. To test add a barracks to France:
<unitPlacement unitType="barracks" territory="France" quantity="1" owner="Germans"/>
Load the game, and now Germany can produce only infantry units in France, but they can also still produce infantry in Germany.
Like I said you had the right ideas, and you went a long way to getting what you wanted. There were just a few things that need to be added or changed. Don't give up now!! Mod! Mod! and Mod some more!!