XML.Colorize
------------

Formats a XML string with color.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [XML](component_XML.md) | [8.2](newinversion82.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "XML.Colorize"; XML { ; DarkMode } ) 

**MBS**( **"XML.Colorize";** /\* Formats a XML string with color. \*/  
**$XML**; /\* The XML text to process.e.g. "&lt;test&gt;Hello&lt;/test&gt;" \*/   
**$DarkMode**) /\* Optional; Whether to swap colors to use white for text color.  
Pass 1 for dark mode and 0 for light mode.  
Default is 0 for light mode.e.g. 0 \*/ 

(old name: XML.Colourise)

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| XML | The XML text to process. | "&lt;test&gt;Hello&lt;/test&gt;" |  |
| DarkMode | Whether to swap colors to use white for text color.   Pass 1 for dark mode and 0 for light mode.   Default is 0 for light mode. | 0 | Optional      Added in version **12.1**. |

### Result

Returns formatted text or error.

### Description

Formats a XML string with color.  
This colorizes an existing XML text to show to user, but does not check syntax.  
Keys get blue, text value black, attributes in purple.  
  
Text is returned only with colors. You can apply text font and font size with normal FileMaker functions.  
Processing time is linear to length, so should be faster than custom functions.  
  
Applying text styles takes time. You may consider to skip this if your JSON is e.g. bigger than a million characters to improve performance of your scripts.  
  
Colors used for JSON and XML colorization:  
  
| What | Light | Dark |
|---|---|---|
| Brackets and commas | \#000000 Black | \#FFFFFF White |
| Object Keys | \#3C4BEB Blue | \#6473FF Blue |
| Text Values | \#AC2C6A Purple | \#D65492 Purple |
| Numbers | \#AF6527 Orange | \#D78D4F Orange |

### Examples

Colorize a field:

 Set Field \[ Data::XML ; MBS ("XML.Colorize"; Data::XML ) \]  
Line numbers, color and format:

 MBS ( "[Text.AddLineNumbers](TextAddLineNumbers.md)"; MBS ( "XML.Colorize"; MBS ( "[XML.Format](XMLFormat.md)"; Buckets::Listing )))  
Colorize in Auto-Enter calculation:

 MBS ("XML.Colorize"; self)  
  
// put this calculation into a field, so the field gets colorized whenever the field is changed and the record gets commited.  
Colorize and format in Auto-Enter calculation:

 Let ( \[  
xmlFormatted = MBS ("[XML.Format](XMLFormat.md)"; Self);  
xmlFormatFailed = MBS ("IsError");  
xmlText = If(xmlFormatFailed; Self; xmlFormatted);  
result = MBS ("XML.Colorize"; xmlText)  
\]; result )  
  
// put this calculation into a field, so the field gets formated and colorized whenever the field is changed and the record gets commited.  
### See also

- [FM.SQL.XMLRecords](FMSQLXMLRecords.md)
- [IsError](IsError.md)
- [Text.AddLineNumbers](TextAddLineNumbers.md)
- [Text.Tidy](TextTidy.md)
- [XML.Format](XMLFormat.md)
- [XML.Tidy](XMLTidy.md)
- [XML.ToHTML](XMLToHTML.md)

### Release notes

- **Version 15.1**
    - Improved [XML.Canonical](https://www.mbsplugins.eu/XMLCanonical.shtml), [XML.Compact](https://www.mbsplugins.eu/XMLCompact.shtml), [XML.Format](https://www.mbsplugins.eu/XMLFormat.shtml) and [XML.Colorize](https://www.mbsplugins.eu/XMLColorize.shtml) functions to return empty text for empty output.
- **Version 12.3**
    - You can now use english spelling [JSON.Colourise](https://www.mbsplugins.eu/JSONColorize.shtml) and [XML.Colourise](https://www.mbsplugins.eu/XMLColorize.shtml) if you prefer to call [JSON.Colorize](https://www.mbsplugins.eu/JSONColorize.shtml) or [XML.Colorize](https://www.mbsplugins.eu/XMLColorize.shtml).
- **Version 12.1**
    - Added darkMode parameter for [XML.Colorize](https://www.mbsplugins.eu/XMLColorize.shtml) and [JSON.Colorize](https://www.mbsplugins.eu/JSONColorize.shtml) function.
- **Version 8.2**
    - Added [XML.Colorize](http://www.mbsplugins.eu/XMLColorize.shtml) function.
    - Fixed [XML.Colorize](http://www.mbsplugins.eu/XMLColorize.shtml) function coloring for attributes.

### Example Databases

- [DynaPDF/List XFA Streams](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/DynaPDF/List%20XFA%20Streams.shtml#4ScriptAnchor_)
- [JSON/JSON to HTML](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JSON/JSON%20to%20HTML.shtml#1292FieldAnchor_)
- [Mac only/Script Workspace Context Menu Commands](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Mac%20only/Script%20Workspace%20Context%20Menu%20Commands.shtml#3ScriptAnchor_)
- [Saxon/Saxon XPath](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Saxon/Saxon%20XPath.shtml#1296FieldAnchor_)
- [Saxon/Saxon XQuery MrWatsons Examples](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Saxon/Saxon%20XQuery%20MrWatsons%20Examples.shtml#1296FieldAnchor_)
- [Saxon/Saxon XQuery](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Saxon/Saxon%20XQuery.shtml#1296FieldAnchor_)
- [Saxon/Saxon XSLT](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Saxon/Saxon%20XSLT.shtml#1296FieldAnchor_)
- [XML/XML and JSON](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/XML/XML%20and%20JSON.shtml#3ScriptAnchor_)
- [XML/XML Colorize](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/XML/XML%20Colorize.shtml#1292FieldAnchor_)
- [XML/XML to HTML](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/XML/XML%20to%20HTML.shtml#1291FieldAnchor_)

### Blog Entries

- [Goodies 46: A format button for the data viewer](https://www.monkeybreadsoftware.com/filemaker/SyntaxColoring/46-FormatButtonDataViewer.shtml)
- [A format button for the data viewer](https://www.mbsplugins.de/archive/2025-07-16/A_format_button_for_the_data_v/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 15.1pr1](https://www.mbsplugins.de/archive/2025-02-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin 12.1 - More than 6700 Functions In One Plugin](https://www.mbsplugins.de/archive/2022-03-15/MBS_FileMaker_Plugin_121_-_Mor/monkeybreadsoftware_blog_filemaker)
- [XML and JSON Colorize for Dark Mode](https://www.mbsplugins.de/archive/2022-01-19/XML_and_JSON_Colorize_for_Dark/monkeybreadsoftware_blog_filemaker)
- [FileMaker Developers in Southern California](https://www.mbsplugins.de/archive/2021-03-15/FileMaker_Developers_in_Southe/monkeybreadsoftware_blog_filemaker)
- [FileMaker records to XML or JSON](https://www.mbsplugins.de/archive/2020-06-30/FileMaker_records_to_XML_or_JS/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin 8.3 released](https://www.mbsplugins.de/archive/2018-07-17/MBS_FileMaker_Plugin_83_releas/monkeybreadsoftware_blog_filemaker)
- [Colorize JSON or XML in FileMaker with line numbers](https://www.mbsplugins.de/archive/2018-05-27/Colorize_JSON_or_XML_in_FileMa/monkeybreadsoftware_blog_filemaker)
- [Colorize XML in FileMaker](https://www.mbsplugins.de/archive/2018-04-08/Colorize_XML_in_FileMaker/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 3/2025, Seite 18](https://filemaker-magazin.de/neuigkeit/4290-Appetithappen-FMM_202503)

This function is free to use.

Created 8th April 2018 , last changed 27th October 2025

  
[XML.ClearVariables](XMLClearVariables.md) - [XML.Compact](XMLCompact.md)

[HTML Version](XMLColorize.shtml)