Skip to main content

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 &amp; -->
<description>Speed & acceleration</description>

<!-- CORRECT -->
<description>Speed &amp; acceleration</description>

Special Characters​

Must be escaped in XML content:

CharacterEscape
&&
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:

  1. Start with XML declaration
  2. Have one root element
  3. Have properly closed tags
  4. Have properly nested elements
  5. Have all special characters escaped
  6. 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​

Best Practices​

  1. Always validate - Check syntax before using
  2. Use proper indentation - 2 or 4 spaces
  3. Add comments - Explain complex sections
  4. Use descriptive names - Clear element names
  5. Escape special characters - Avoid syntax errors
  6. Backup originals - Before making changes
  7. 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.