Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old


Extracts a given subtree.

Component Version macOS Windows Linux Server iOS SDK
XML 7.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "XML.SubTree"; XML; Name { ; Flags; Index } )   More


Parameter Description Example Flags
XML The XML to process.
Can be XML as text or the reference returned by XML.Parse function, so you can make several times changes to the XML without parsing it each time.
Name The name of the node to query.
This can be a list to go over several steps to the target tree part.
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 if you do not like the XML to be formatted.
Add 8 to remove all namespaces before query to have queries easier. (new in 6.3)
0 Optional
Index The index of the item to get.
First has index 0 as this counts down how many to skip.
0 Optional


Returns xml or error message.


Extracts a given subtree.
You can pass an index to get nth item.
Returns empty result if index is too high, so you can loop until you get empty result.


Query person entry:

MBS( "XML.SubTree"; "<People><Person><FirstName>Markus</FirstName><LastName>Müller</LastName><City>New York</City></Person></People>"; "Person")

Example result:
<?xml version="1.0" encoding="UTF-8"?>
  <City>New York</City>

Queries values:

Set Variable [$xml; Value:"<a><b>123</b><b>456</b><b>789</b></a>"]
Show Custom Dialog ["First item:"; MBS( "XML.ExtractText"; MBS( "XML.SubTree"; $xml; "b"; 0; 0))]
Show Custom Dialog ["Second item:"; MBS( "XML.ExtractText"; MBS( "XML.SubTree"; $xml; "b"; 0; 1))]
Show Custom Dialog ["Third item:"; MBS( "XML.ExtractText"; MBS( "XML.SubTree"; $xml; "b"; 0; 2))]

Query data in SOAP Webservice response:

MBS( "XML.SubTree"; $XML; "Envelope¶Body¶AdressCheckerResponse¶rows")

Custom function to get xml value as text:

GetXMLValue(xml, name)

# returns text of a xml node

Let ([
part = MBS( "XML.SubTree"; xml; name);
result = If( MBS("IsError"); ""; If(Length(part) = 0; ""; MBS( "XML.ExtractText"; part)))
]; Trim( result))

Create records and fill fields with xml values:

Go to Layout [“XML Parser”]
# find the node with all the records we need:
Set Variable [$oxml; Value:MBS( "XML.SubTree"; XML Parser::Input XML; "Body¶GetCategoryProductsResponse" )]
# query number of products
Set Variable [$count; Value:MBS( "XML.NodeCount"; $oxml; "PRODUCT")]
# loop over products
Set Variable [$index; Value:0]
    # get a product
    Set Variable [$xml; Value:MBS( "XML.SubTree"; $oxml; "PRODUCT"; $index)]
    # get the names of the XML nodes
    Set Variable [$names; Value:MBS( "XML.NodeNames"; $xml; 0; 16)]
    # loop over the names
    Set Variable [$NameCount; Value:ValueCount ( $names )]
    Set Variable [$NameIndex; Value:1]
    New Record/Request
        # Query a value and put it in a field
        Set Variable [$name; Value:GetValue($names; $NameIndex)]
        Set Field By Name ["XML Parser::" & $name; GetXMLValue( $xml; $name)]
        Set Variable [$NameIndex; Value:$NameIndex + 1]
        Exit Loop If [$NameIndex$NameCount]
    End Loop
    Commit Records/Requests [No dialog]
    Set Variable [$index; Value:$index + 1]
    Exit Loop If [$index > $count]
End Loop

See also

Release notes

Example Databases

Blog Entries

This function checks for a license.

Created 25th December 2016, last changed 9th October 2020

XML.SetVariables - XML.ToHTML