XML.SetVariables
----------------

Creates local variables in script for XML nodes.

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

MBS( "XML.SetVariables"; XML { ; Recursive; Flags; Prefix } ) 

**MBS**( **"XML.SetVariables";** /\* Creates local variables in script for XML nodes. \*/  
**$XML**; /\* The XML to process.  
Can be XML as text or the reference returned by [XML.Parse](XMLParse.md) function, so you can make several times queries to the XML without parsing it each time.e.g. "&lt;test&gt;Hello&lt;/test&gt;" \*/   
**$Recursive**; /\* Optional; Whether to recurse in sub tree.  
Pass 1 for rescursive or 0 for non-recursive.  
Default is 0.e.g. 1 \*/   
**$Flags**; /\* Optional; Various Flags.  
Add 1 to ignore errors in xml and continue parsing. This may lead to not everything in the xml being read.e.g. 0 \*/   
**$Prefix**) /\* Optional; The prefix to use for the variables names.e.g. "" \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| XML | The XML to process.   Can be XML as text or the reference returned by [XML.Parse](XMLParse.md) function, so you can make several times queries to the XML without parsing it each time. | "&lt;test&gt;Hello&lt;/test&gt;" |  |
| Recursive | Whether to recurse in sub tree.   Pass 1 for rescursive or 0 for non-recursive.   Default is 0. | 1 | Optional |
| Flags | Various Flags.   Add 1 to ignore errors in xml and continue parsing. This may lead to not everything in the xml being read. | 0 | Optional |
| Prefix | The prefix to use for the variables names. | "" | Optional |

### Result

Returns list or error.

### Description

Creates local variables in script for XML nodes.  
Returns list of variable names.  
If variables receive multiple values the name in the result comes the highest index in square brackets.  
  
You can call [XML.ClearVariables](XMLClearVariables.md) later to clear those variables, but at the end of the script all variables will go away. Variable names are shortened in v12.5 and newer to a maximum of 100 characters.  
### Examples

Set variables:

 MBS ( "XML.SetVariables"; "&lt;Person&gt;&lt;FirstName&gt;Markus&lt;/FirstName&gt;&lt;LastName&gt;Müller&lt;/LastName&gt;&lt;City&gt;New York&lt;/City&gt;&lt;/Person&gt;")  
<small>  
Example result:   
LastName  
City  
FirstName</small>### See also

- [JSON.SetVariables](JSONSetVariables.md)
- [OCR.SetVariable](OCRSetVariable.md)
- [XML.ClearVariables](XMLClearVariables.md)
- [XML.Parse](XMLParse.md)

### Release notes

- **Version 15.0**
    - Improved [JSON.SetVariables](https://www.mbsplugins.eu/JSONSetVariables.shtml) and [XML.SetVariables](https://www.mbsplugins.eu/XMLSetVariables.shtml) functions to work better with multi line texts.
- **Version 12.5**
    - Fixed a problem in [XML.SetVariables](https://www.mbsplugins.eu/XMLSetVariables.shtml) and long variable names.
- **Version 11.4**
    - Changed [XML.SetVariables](https://www.mbsplugins.eu/XMLSetVariables.shtml) to assign XML block if item is a xml tree and not recursive.
- **Version 7.0**
    - Added XML helper functions: [XML.ExtractText](http://www.mbsplugins.eu/XMLExtractText.shtml), [XML.NodeNames](http://www.mbsplugins.eu/XMLNodeNames.shtml), [XML.SetVariables](http://www.mbsplugins.eu/XMLSetVariables.shtml), [XML.ListAttributes](http://www.mbsplugins.eu/XMLListAttributes.shtml), XML.HasAttributes, XML.GetAttributes and [XML.SubTree](http://www.mbsplugins.eu/XMLSubTree.shtml).

### Example Databases

- [XML/XML Test](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/XML/XML%20Test.shtml#3ScriptAnchor_)

### Blog Entries

- [MBS FileMaker Plugin, version 15.0pr7](https://www.mbsplugins.de/archive/2025-01-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 12.5pr1](https://www.mbsplugins.de/archive/2022-09-29/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 11.4pr2](https://www.mbsplugins.de/archive/2021-08-11/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 7.0pr1](https://www.mbsplugins.de/archive/2017-01-02/MBS_FileMaker_Plugin_version_7/monkeybreadsoftware_blog_filemaker)
- [New XML Functions in MBS FileMaker Plugin](https://www.mbsplugins.de/archive/2016-12-27/New_XML_Functions_in_MBS_FileM/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 3/2017, Seite 27](https://filemaker-magazin.de/neuigkeit/3938-Appetithappen-FMM_201703)

This function checks for a license.

Created 25th December 2016 , last changed 25th November 2024

  
[XML.SetSaveNoEmptyTags](XMLSetSaveNoEmptyTags.md) - [XML.SubTree](XMLSubTree.md)

[HTML Version](XMLSetVariables.shtml)