Topics
All
MacOS
(Only)
Windows
(Only)
Linux
(Only, Not)
iOS
(Only, Not)
Components
Crossplatform Mac & Win
Server
Client
Old
Deprecated
Guides
Examples
Videos
New in version:
9.5
10.0
10.1
10.2
10.3
10.4
10.5
11.0
11.1
11.2
Statistic
FMM
Blog
Extracts a given subtree.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
XML | 7.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
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. |
"<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. |
"something" | |
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.
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"?>
<Person>
<FirstName>Markus</FirstName>
<LastName>Müller</LastName>
<City>New York</City>
</Person>
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]
Loop
# 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
Loop
# 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
Created 25th December 2016, last changed 9th October 2020
Feedback: Report problem or ask question.