Lesson 1.1 – What is XML and Why Does Bannerlord Use It?
What is XML?
XML stands for Extensible Markup Language. It’s not a programming language – it’s a data format.
It’s like a digital filing system. XML uses tags (like <Troop> or <Kingdom>) to wrap around and organize information. Those tags has properly opening and closing structure, to ensure its functionality. For example:
<skills> opens the container skills where they will be defined.
</skills> closes the container.
Before progressing to any other container, those opening and closing need to be attentivelly checked to avoid crashes.
Why Bannerlord Uses XML:
Game data definition: Troops, weapons, kingdoms, settlements – they're all defined in XML.
Modding-friendly: You don’t need to write C# or compile code to tweak values or create new game content.
Flexible: Add new things without rewriting the game – just reference your additions properly.
Think of it like this:
If the game engine is the brain, then XML is the memory – it stores the game’s knowledge about what exists.
On the example in the right columm we see a xml structure used in bannerlord.
Below we have the key XML Structure Concepts Illustrated:
-
Root Element: The entire definition for this troop is contained within the <NPCCharacter> ... </NPCCharacter> tags. This is the main element describing this specific object.
-
Child Elements: Tags nested directly inside <NPCCharacter>, like <face>, <skills>, <upgrade_targets>, and <Equipments>, are its children. They represent major categories of properties for the character.
-
Nesting / Hierarchy: Elements can be nested further. <skill> is a child of <skills>, and <equipment> is a child of <EquipmentRoster>, which is a child of <Equipments>. This creates a structured hierarchy, like folders within folders.
-
Tags vs. Attributes:
-
Tags (<element_name>) define the structure and type of data (e.g., <skills> holds skill information).
-
Attributes (attribute_name="value") provide specific details about an element (e.g., the id attribute gives the unique name, the value attribute gives the skill level). Attributes are always inside the opening tag.
XML uses tags (like <book>) to define elements and attributes (like id="bk101" inside the opening tag) to provide specific details about those elements.
-
-
Opening and Closing Tags: Most elements have an opening tag (e.g., <skills>) and a corresponding closing tag (</skills>). Everything between them is the content or child elements of that element.
-
Self-Closing Tags: Some tags, like <skill ... /> or <equipment ... />, don't contain any other elements between them. They represent a single piece of information defined entirely by their attributes. They can be written with a / before the final > as a shortcut.
-
Comments: <!-- ... --> blocks are ignored by the game but crucial for explaining complex parts or marking your changes. Use them!
-
Readability: Notice the indentation. While not required by the XML parser, it's vital for humans to easily see the structure and relationships between elements. Use your editor's formatting tools!
XML example as viewed inside VS Code:

Complete troop xml (all necessary containers)
<NPCCharacter
id="imperial_recruit"
default_group="Infantry"
level="6"
name="{=s3IJIFUw}Imperial Recruit"
occupation="Soldier"
is_basic_troop="true"
culture="Culture.empire">
<face>
<face_key_template
value="BodyProperty.fighter_empire" />
</face>
<skills>
<skill
id="Athletics"
value="20" />
<skill
id="Riding"
value="0" />
<skill
id="OneHanded"
value="20" />
</skills>
<upgrade_targets>
<upgrade_target
id="NPCCharacter.imperial_infantryman" />
<Equipments>
<EquipmentRoster>
<equipment
slot="Item0"
id="Item.peasant_pitchfork_2_t1" />
<equipment
slot="Head"
id="Item.leather_cap" />
<equipment
slot="Body"
id="Item.tunic_with_shoulder_pads" />
<equipment
slot="Leg"
id="Item.empire_horseman_boots" />
</EquipmentRoster>
<EquipmentSet
id="empire_troop_civilian_template_t1"
civilian="true" />
</Equipments>
</NPCCharacter>
Improved Lesson 1.2 – How Bannerlord organize its XML structures
How are the XMLs organized in game?
When you open your Mount & Blade II: Bannerlord installation folder and navigate to Modules, you will see the vanilla (vanilla = base game) folders inside it. These are the official game modules provided by the developers. Inside those folders, you will find, among other essential content, the game’s XML files, which are located in a subfolder called ModuleData.
These XML files define many aspects of the game, such as troop trees, items, lords, clans, kingdoms, and more. Each XML file has its own specific name and function. However, simply creating or editing an XML file is not enough — the game needs to know which XML files to load. This is where the SubModule.xml file comes in.
The SubModule.xml is a critical configuration file found outside the ModuleData folder, in the root of your module directory. It acts as the main descriptor for your mod and tells the game how to load your module. Inside the SubModule.xml, you will reference all your custom XML files so the game can recognize and integrate them during startup.
Additionally, the SubModule.xml defines your mod’s dependencies (other modules it relies on), the order in which your mod should be loaded, and can also specify custom code (DLLs) if your mod includes C# scripts. Properly configuring this file is essential for your mod to function correctly.
Inside the SubModule.xml, you will:
-
Declare your module's name and ID.
-
Set the module category (such as "Singleplayer" or "Multiplayer").
-
Reference all your custom XML files in the <Xmls> section.
-
Define any module dependencies in the <DependentModules> section.
-
Optionally, specify your DLL (if you are using custom code).
By correctly setting up your SubModule.xml, you ensure that the game engine recognizes your mod and loads all the necessary data, bringing your custom creations into the world of Bannerlord
Watch the video lesson below

xml_introduction
Improved Lesson 1.3 – XML vs. Programming: Defining Data vs. Defining Actions
Understanding the Roles: XML vs. C# Code
It's crucial to understand that XML is not a programming language like C# (the language Bannerlord's engine primarily uses). They serve very different, but complementary, purposes:
-
XML (Markup Language): Focuses on Data and Structure
-
It describes what things are and their properties.
-
Think of it as creating detailed lists and blueprints.
-
Example: "This <NPCCharacter> block defines a troop. Its id is imperial_recruit, its level is 6, and it uses this specific equipment (<equipment ... />)."
-
XML files essentially act as configuration data or databases for the game.
-
-
C# (Programming Language): Focuses on Behavior and Logic
-
It describes what things do and the rules they follow.
-
Think of it as writing instructions, procedures, and decision-making processes.
-
Example: "This C# code makes an NPC decide which enemy to target, calculate the damage when its weapon hits, and determine if it should block or flee based on its health."
-
How They Work Together in Bannerlord:
When Bannerlord starts up or loads data, its core C# game engine reads the XML files. The engine understands that an <NPCCharacter> tag means "load the definition of a character" and uses the attributes (id, level, skills, etc.) defined in the XML to create that character's data inside the game's memory.
Later, during gameplay, the C# code uses that data (loaded from XML) to run the simulation – moving troops, resolving combat, handling AI, etc.
Analogy: The Blueprint and the Construction Crew
This is a great way to visualize it:
-
XML is the detailed blueprint for a house. It defines the number of rooms, their dimensions, the materials to use (wood, brick), the placement of doors and windows – essentially, what the house is made of and its structure.
-
C# Code is the construction crew and their tools. They read the blueprint and perform the actions needed to build the house – pouring the foundation, framing the walls, installing the plumbing, wiring the electricity – following the specifications laid out in the blueprint.
The crew can't build without the blueprint, and the blueprint doesn't build anything by itself.
What Can You Control with Just XML in Bannerlord?
XML gives you tremendous power over the game's data. Here's a quick overview:
Game SystemControlled Primarily by XML
Troops & Upgrade Trees ✅ Yes Define stats, skills, appearance, equipment, and how troops upgrade.
Lords, Clans, Kingdoms ✅ Yes Define characters, families, factions, their members, culture, banners, colors, relationships.
Items (Weapons, Armor) ✅ Yes Define item stats, appearance, cost, properties (e.g., swing/thrust damage, armor value).
Cultures ✅ Yes Define cultural traits, naming, base relations, default troops.
Dialogue ✅ Yes (Content/Structure)XML (often via separate localization files) holds the dialogue text lines and basic connections.
Quests & Game Logic ❌ (Complex Logic)XML might define quest text or basic rewards, but C# is needed for branching logic, triggers, conditions.
AI Behavior ❌ (Core Logic)XML defines troop stats which influence AI, but the core decision-making AI is C#.
New Game Mechanics ❌ Adding fundamentally new features (e.g., magic system, naval combat) requires C# programming.
(Note on Dialogue/Quests: While XML holds text, complex choices or quest steps that check game conditions or trigger unique events usually require C# intervention.)
You'll typically find Bannerlord's core XML files within the game's Modules directory, often inside Bannerlord/ModuleData subfolders. We'll explore specific files later.
The Power of XML Modding:
This separation is fantastic for modders! It means you can use XML alone to make significant and exciting changes to Bannerlord. You can create entirely new factions with unique troop trees, add custom lords and clans, introduce powerful new items, and rebalance existing ones – all by editing these structured data files, often without needing to dive into complex C# programming. This makes a huge range of modding accessible to beginners!
Recommended tolls for editing xml:
1. Visual Studio Code (VS Code)
-
✅ Cross-platform (Windows, Mac, Linux)
-
✅ Powerful extensions for XML
-
✅ Built-in Git & project navigation
-
🧩 Add the "XML Tools" or "XML Language Support" extensions for formatting and validation.
Get it here: https://code.visualstudio.com
2. Notepad++ (Windows only)
-
✅ Lightweight and fast
-
✅ Excellent syntax highlighting
-
✅ Easy to use for beginners
Get it here: https://notepad-plus-plus.org
Think of it like this:
If the game engine is the brain, then XML is the memory – it stores the game’s knowledge about what exists.
💡 Pro Tips When Editing XML:
Feature Why It Helps
Syntax Highlighting Makes tags and values easier to read
Code Folding Collapse large blocks (like troop entries) to stay organized
Auto-Indentation Helps visualize nested data structure
Find/Replace (Ctrl+F / Ctrl+H) Quickly locate IDs or attributes
XML Validator Detect missing tags or typos before crashing the game
🚨 XML is strict.
The game will crash if:
-
A tag is not closed (</NPCCharacter> missing)
-
Quotes are mismatched (id="value instead of id="value")
-
You forget a required attribute
-
You reuse an ID that already exists
✅ Safe Workflow:
-
Back up the file before editing.
-
Edit carefully in VS Code or Notepad++.
-
Validate the XML:
-
Use an online tool like https://www.xmlvalidation.com
-
Or install an extension that shows errors live in VS Code.
-
-
Save and launch the game.
-
Start a new sandbox game to test changes.
-
Basic Navigation and Editing Tips:
-
Syntax Highlighting: Notice how tags (<tag>), attributes (attribute=), and values ("value") are colored differently. This helps spot errors.
-
Indentation: Proper indentation makes XML readable. Most editors can auto-format (check menus or extension features like Format Document in VS Code). XML itself doesn't require indentation to work, but humans do!
-
Find/Replace: Use Ctrl+F (Find) and Ctrl+H (Replace) to locate specific IDs, values, or tags quickly.
-
Code Folding: Look for small [-] or [+] icons (or arrows) in the margin next to line numbers. Clicking these collapses or expands sections, invaluable for large files like spnpccharacters.xml.
-
-
Opening Files:
Use File > Open or drag-and-drop XML files into the editor window. Find Bannerlord's XMLs in ...\Mount & Blade II Bannerlord\Modules\SandBoxCore\ModuleData\ and other module folders.
Always back up original files before editing! Consider creating a separate mod folder.
Action Item: Choose either Notepad++ or VS Code, download, and install it. Try opening one of Bannerlord's XML files (like spitems.xml) to see the syntax highlighting and try collapsing/expanding some elements.
Final Takeaways from Section 1
✅ XML is a data format, not a programming language. They are ultra sensitive, any typo mistake will crashe the game.
✅ Bannerlord uses it everywhere for troops, factions, items, and more.
✅ You only need a good editor and some careful attention to start modding.
✅ Validation and testing are key to avoiding crashes.
✅ Next, you'll dive into troop creation!