Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server (Not)   Client   Old   Guides   Examples
New in version: 6.1   6.2   6.3   6.4   6.5   7.0   7.1   7.2   7.3   7.4    Statistic  


Extracts a given subtree.

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
XML 7.0 Yes Yes Yes Yes Yes

MBS( "XML.SubTree"; XML; Name { ; Flags; Index } )


Parameter Description Example value
XML The XML to process. "<test>Hello</test>"
Name The name of the node to query.
This can be a list to go over several steps to the target tree part.
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.
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)
Index Optional
The index of the item to get.
First has index 0 as this counts down how many to skip.


Returns OK or error.


Extracts a given subtree.
You can pass an index to get nth item.


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

Example Databases

XML.SetVariables   -   ZipFile.CRCFile

Feedback: Report problem or ask question.

MBS Xojo Chart Plugins