# XML in Basalt
Basalt provides an XML parser that lets you define your UI layout in a declarative way. This can make your code more readable and maintainable.
## Basic Usage
```lua
local main = basalt.getMainFrame()
-- Load from file
local xmlFile = fs.open("myUI.xml", "r")
main:loadXML(xmlFile.readAll())
xmlFile.close()
-- Or directly as string
main:loadXML([[
]])
```
## Working with Variables
The XML parser uses a scope system to access variables and functions. Any variables you want to use in your XML must be passed in the scope:
```lua
local scope = {
title = "My App",
buttonWidth = 10,
handleClick = function(self)
self:setText("Clicked!")
end
}
main:loadXML([[
]], scope)
```
## Event Handlers
There are two ways to define event handlers:
### 1. Reference a Function in Scope
```lua
local scope = {
btnClick = function(self)
self:setText("Clicked!")
end
}
main:loadXML([[
]], scope)
```
### 2. Using CDATA Sections
```xml
```
## Property Types
The XML parser automatically converts values based on the property type:
```xml