XML.SetPathXML
--------------

Sets path value with XML sub tree.

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

MBS( "XML.SetPathXML"; XML; Path; Flags; NewXML ) 

**MBS**( **"XML.SetPathXML";** /\* Sets path value with XML sub tree. \*/  
**$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 changes to the XML without parsing it each time.e.g. "&lt;test&gt;Hello&lt;/test&gt;" \*/   
**$Path**; /\* The path to the node or attribute to query.e.g. "name" \*/   
**$Flags**; /\* Various Flags.  
Add 1 to ignore errors in xml and continue parsing. This may lead to not everything in the xml being read.  
Add 4 to format returned XML.  
Add 32 to return result as XML.e.g. 0 \*/   
**$NewXML**) /\* The new xml for node or attribute.  
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;name&gt;Christian&lt;/name&gt;" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| 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 changes to the XML without parsing it each time. | "&lt;test&gt;Hello&lt;/test&gt;" |
| Path | The path to the node or attribute to query. | "name" |
| Flags | Various Flags.   Add 1 to ignore errors in xml and continue parsing. This may lead to not everything in the xml being read.   Add 4 to format returned XML.   Add 32 to return result as XML. | 0 |
| NewXML | The new xml for node or attribute.   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;name&gt;Christian&lt;/name&gt;" |

### Result

Returns XML, OK or error.

### Description

Sets path value with XML sub tree.  
If needed, new nodes / attributes are added.  
This function uses a path notation like the [JSON](component_JSON.md) functions in FileMaker to describe paths. Please point with path to new node.  
You can use name of a node followed by optional index in square brackets. On the end you can use # followed by a name of an attribute to select only the attribute. Empty brackets or too big index allow you to append new node.  
Delimiter between items can be dot like FileMaker or newline.  
  
If you pass in a XML reference number and you do not pass Flag value 32 for returning as XML, we just modify the XML reference in memory. This avoids performance hit for outputting and parsing xml for each change.  
### Examples

Insert new node:

 MBS ("XML.SetPathXML"; "&lt;export&gt;&lt;person&gt;&lt;/person&gt;&lt;/export&gt;"; "export¶person¶name"; 0; "&lt;name&gt;Test&lt;/name&gt;")  
<small>  
Example result:   
&lt;?xml version="1.0" encoding="UTF-8"?&gt;  
&lt;export&gt;&lt;person&gt;&lt;name&gt;Test&lt;/name&gt;&lt;/person&gt;&lt;/export&gt;</small>Insert second node with index:

 MBS ("XML.SetPathXML"; "&lt;export&gt;&lt;person&gt;&lt;name&gt;First&lt;/name&gt;&lt;/person&gt;&lt;/export&gt;"; "export¶person¶name\[1\]"; 0; "&lt;name&gt;Test&lt;/name&gt;")  
<small>  
Example result:   
&lt;?xml version="1.0" encoding="UTF-8"?&gt;  
&lt;export&gt;&lt;person&gt;&lt;name&gt;First&lt;/name&gt;&lt;name&gt;Test&lt;/name&gt;&lt;/person&gt;&lt;/export&gt;</small>Append node:

 MBS ("XML.SetPathXML"; "&lt;export&gt;&lt;person&gt;&lt;name&gt;First&lt;/name&gt;&lt;/person&gt;&lt;/export&gt;"; "export¶person¶name\[\]"; 0; "&lt;name&gt;Test&lt;/name&gt;")  
Set XML part with namespaces:

 MBS ("XML.SetPathXML"; "&lt;r:export ns:r=\\"http://mbsplugins.eu/testNamespace\\"&gt;&lt;r:person&gt;&lt;/r:person&gt;&lt;/r:export&gt;"; "r:export¶r:person¶r:name"; 0; "&lt;name&gt;Test&lt;/name&gt;")  
<small>  
Example result:   
&lt;?xml version="1.0" encoding="UTF-8"?&gt;  
&lt;r:export ns:r="http://mbsplugins.eu/testNamespace"&gt;&lt;r:person&gt;&lt;name&gt;Test&lt;/name&gt;&lt;/r:person&gt;&lt;/r:export&gt;</small>### See also

- [FM.SQL.XMLRecords](FMSQLXMLRecords.md)
- [XML.Parse](XMLParse.md)
- [XML.SetPathValue](XMLSetPathValue.md)

### Release notes

- **Version 8.1**
    - Added [XML.SetPathXML](http://www.mbsplugins.eu/XMLSetPathXML.shtml) function.
    - For [XML.SetPathValue](http://www.mbsplugins.eu/XMLSetPathValue.shtml) and [XML.SetPathXML](http://www.mbsplugins.eu/XMLSetPathXML.shtml) you can now specify \[\] (Without index) to add new node on the end.

### Blog Entries

- [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 v8.1 with 5100 Functions In One Plugin](https://www.mbsplugins.de/archive/2018-03-06/MBS_FileMaker_Plugin_v81_with_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin 8.1](https://www.mbsplugins.de/archive/2018-03-06/MBS_FileMaker_Plugin_81/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 8.1pr1](https://www.mbsplugins.de/archive/2018-02-02/MBS_FileMaker_Plugin_version_8/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

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

This function checks for a license.

Created 2nd February 2018 , last changed 30th June 2022

  
[XML.SetPathValue](XMLSetPathValue.md) - [XML.SetSaveNoEmptyTags](XMLSetSaveNoEmptyTags.md)

[HTML Version](XMLSetPathXML.shtml)