XML.SetPathValue
----------------

Sets a xml node.

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

MBS( "XML.SetPathValue"; XML; Path; Flags; Value ) 

**MBS**( **"XML.SetPathValue";** /\* Sets a xml node. \*/  
**$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 \*/   
**$Value**) /\* The new value for node or attribute.  
This is for passing text to be used in XML and encoded properly.  
If you pass new value as XML, please use [XML.SetPathXML](XMLSetPathXML.md) instead!.e.g. "Hello" \*/ 

### 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 |
| Value | The new value for node or attribute.   This is for passing text to be used in XML and encoded properly.   If you pass new value as XML, please use [XML.SetPathXML](XMLSetPathXML.md) instead!. | "Hello" |

### Result

Returns XML, OK or error.

### Description

Sets a xml node.  
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.  
You can use name of a node followed by option 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 in v8.1.  
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

Add a first name:

 MBS ( "XML.SetPathValue"; "&lt;person/&gt;"; "person.firstName"; 0; "Joe" )  
<small>  
Example result:   
"&lt;?xml version="1.0" encoding="UTF-8"?&gt;  
&lt;person&gt;&lt;firstName&gt;Joe&lt;/firstName&gt;&lt;/person&gt;"</small>Add id attribute:

 MBS ( "XML.SetPathValue"; "&lt;person/&gt;"; "person#id"; 0; "123" )  
<small>  
Example result:   
"&lt;?xml version="1.0" encoding="UTF-8"?&gt;  
&lt;person id="123"/&gt;"</small>Adds a new name node with href number.

 MBS ( "XML.SetPathValue"; "&lt;person&gt;&lt;/person&gt;"; "person.name href=10" ; 4 ; "" )  
<small>  
Example result:   
&lt;?xml version="1.0" encoding="UTF-8"?&gt;  
&lt;person&gt;  
 &lt;name href=10&gt;&lt;/name href=10&gt;  
&lt;/person&gt;</small>Encode with entities:

 MBS ("XML.SetPathValue" ; "&lt;foo/&gt;" ; "foo.bar" ; 0 ; "test &amp; test ¶ &lt; &gt; ")  
<small>  
Example result:   
&lt;?xml version="1.0" encoding="UTF-8"?&gt;  
&lt;foo&gt;&lt;bar&gt;test &amp;amp; test &amp;#13; &amp;lt; &amp;gt; &lt;/bar&gt;&lt;/foo&gt;</small>Adds third item to array:

 MBS ( "XML.SetPathValue"; "&lt;person&gt;&lt;firstName&gt;Joe1&lt;/firstName&gt;&lt;firstName&gt;Joe2&lt;/firstName&gt;&lt;/person&gt;"; "person.firstName\[\]"; 0; "Joe3" )  
<small>  
Example result:   
&lt;?xml version="1.0" encoding="UTF-8"?&gt;  
&lt;person&gt;&lt;firstName&gt;Joe1&lt;/firstName&gt;&lt;firstName&gt;Joe2&lt;/firstName&gt;&lt;firstName&gt;Joe3&lt;/firstName&gt;&lt;/person&gt;</small>### See also

- [XML.GetPathValue](XMLGetPathValue.md)
- [XML.Parse](XMLParse.md)
- [XML.SetPathXML](XMLSetPathXML.md)

### Release notes

- **Version 15.0**
    - Improved [XML.SetPathValue](https://www.mbsplugins.eu/XMLSetPathValue.shtml) to not create duplicate nodes when finding them using namespaces.
- **Version 12.2**
    - Changed [XML.SetPathValue](https://www.mbsplugins.eu/XMLSetPathValue.shtml) to create text note if needed.
- **Version 8.1**
    - 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.
- **Version 7.4**
    - Added [XML.GetPathValue](http://www.mbsplugins.eu/XMLGetPathValue.shtml), [XML.DeletePath](http://www.mbsplugins.eu/XMLDeletePath.shtml) and [XML.SetPathValue](http://www.mbsplugins.eu/XMLSetPathValue.shtml) functions.

### Example Databases

- [CURL/Amazon S3/Amazon S3 Upload File](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/Amazon%20S3/Amazon%20S3%20Upload%20File.shtml#9ScriptAnchor_)
- [DynaPDF/ZUGFeRD and Facture-X/ZUGFeRD Rechnung erstellen](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/DynaPDF/ZUGFeRD%20and%20Facture-X/ZUGFeRD%20Rechnung%20erstellen.shtml#17ScriptAnchor_)

### Blog Entries

- [Electronic invoices in FileMaker](https://www.mbsplugins.de/archive/2025-03-06/Electronic_invoices_in_FileMak/monkeybreadsoftware_blog_filemaker)
- [Elektronische Rechnungen in FileMaker](https://www.mbsplugins.de/archive/2025-03-04/Elektronische_Rechnungen_in_Fi/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 14.6pr2](https://www.mbsplugins.de/archive/2024-12-05/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 12.2pr3](https://www.mbsplugins.de/archive/2022-04-21/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)
- [Fun with While function in FileMaker](https://www.mbsplugins.de/archive/2019-07-22/Fun_with_While_function_in_Fil/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)
- [MBS FileMaker Plugin, version 7.4pr6](https://www.mbsplugins.de/archive/2017-09-17/MBS_FileMaker_Plugin_version_7/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 16th September 2017 , last changed 18th April 2022

  
[XML.SetPathCData](XMLSetPathCData.md) - [XML.SetPathXML](XMLSetPathXML.md)

[HTML Version](XMLSetPathValue.shtml)