XML Basics
Introduction to XML and how it's used in FiveM vehicle modding.
What is XML?
XML (eXtensible Markup Language) is a text-based format for storing and organizing structured data. It's used extensively in FiveM for configuration files.
XML Syntax
Elements
<element>content</element>
Attributes
<element attribute="value">content</element>
Complete Example
<?xml version="1.0" encoding="UTF-8"?>
<root>
<item id="1">
<name>Example</name>
<value>100</value>
</item>
</root>
Key Components
XML Declaration
<?xml version="1.0" encoding="UTF-8"?>
- Must be first line
- Declares XML version and encoding
Root Element
<root>
<!-- All content must be inside one root element -->
</root>
Child Elements
<parent>
<child>content</child>
<child>more content</child>
</parent>
Attributes
<vehicle id="1" type="car" class="5">
<name>My Vehicle</name>
</vehicle>
Data Types
Text Content
<name>John Doe</name>
<description>A custom vehicle mod</description>
Numbers
<mass>1500.0</mass>
<acceleration>0.85</acceleration>
<count>5</count>
Boolean Values
<enabled>true</enabled>
<custom>false</custom>
Common Mistakes
Unclosed Tags
<!-- WRONG -->
<name>Vehicle</name>
<!-- CORRECT -->
<name>Vehicle</name>
Improper Nesting
<!-- WRONG -->
<parent>
<child>content</parent>
</child>
<!-- CORRECT -->
<parent>
<child>content</child>
</parent>
Missing XML Declaration
<!-- WRONG - Missing declaration -->
<root>
<item>value</item>
</root>
<!-- CORRECT -->
<?xml version="1.0" encoding="UTF-8"?>
<root>
<item>value</item>
</root>
Invalid Characters
<!-- WRONG - & must be & -->
<description>Speed & acceleration</description>
<!-- CORRECT -->
<description>Speed & acceleration</description>
Special Characters
Must be escaped in XML content:
| Character | Escape |
|---|---|
| & | & |
| Open bracket | < |
| Close bracket | > |
| " | " |
| ' | ' |
Example:
<note>The value must be less than 100 and greater than 0</note>
Comments
<!-- This is a comment -->
<vehicle>
<!-- Comments can be on separate lines -->
<name>Example</name> <!-- Or inline -->
</vehicle>
Indentation & Formatting
Proper indentation makes XML readable:
<?xml version="1.0" encoding="UTF-8"?>
<VehicleFile>
<Vehicles>
<Vehicle id="1">
<Properties>
<Name>Car 1</Name>
<Speed>200</Speed>
</Properties>
</Vehicle>
</Vehicles>
</VehicleFile>
FiveM Vehicle XML Files
carcols.xml (Colors)
<?xml version="1.0" encoding="UTF-8"?>
<colors>
<colour id="0">
<name>Black</name>
<r>15</r>
<g>15</g>
<b>15</b>
</colour>
</colors>
carvariations.xml (Variations)
<?xml version="1.0" encoding="UTF-8"?>
<CVehicleVariationsFile>
<Variations>
<Item>
<modelName>adder</modelName>
<colors>
<color id="0">
<primaryColour>0</primaryColour>
</color>
</colors>
</Item>
</Variations>
</CVehicleVariationsFile>
Validation
Valid XML must:
- Start with XML declaration
- Have one root element
- Have properly closed tags
- Have properly nested elements
- Have all special characters escaped
- Have proper attribute syntax
Tools for Editing
VS Code
- Install "XML" extension
- Auto-formatting with Alt+Shift+F
- Real-time validation
Notepad++
- Built-in XML support
- Syntax highlighting
- Tag matching
Online Validators
- XML Validator
- Check syntax online
- Identify errors quickly
Best Practices
- Always validate - Check syntax before using
- Use proper indentation - 2 or 4 spaces
- Add comments - Explain complex sections
- Use descriptive names - Clear element names
- Escape special characters - Avoid syntax errors
- Backup originals - Before making changes
- Test thoroughly - Verify all values in-game
Common XML Issues in FiveM
- File won't load - Syntax error, check validation
- Missing data - Check element spelling and case
- Numbers not applying - Verify data type is correct
- Special characters broken - Missing XML escape sequences
- Unexpected behavior - Element names don't match references
Next Steps
Now that you understand XML basics, proceed to Common Attributes for FiveM-specific XML structure.