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.2   6.3   6.4   6.5   7.0   7.1   7.2   7.3   7.4   7.5    Statistic  

XML.Query

Performs an XPath query.

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

MBS( "XML.Query"; xml; path { ; namespaceList; Flags } )

Parameters

Parameter Description Example value
xml The XML you'd like to parse. "<hello>Hello World</hello>"
path The XPath you'd like to query. "/*"
namespaceList Optional
List of namespaces. This is a list of known namespaces in "<prefix1>=<href1> <prefix2>=href2> ..." format.
"SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/"
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 2 to return a list of xml nodes as text instead of xml. (new in 5.4)
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

Result

Returns xml text.

Description

Performs an XPath query.
Result is either simple text, a xml node or several xml nodes in a result root node. XML is returned formatted.
Please check on the web for XPath manuals and tutorials.
Version 3.4 of the plugins now also return string, number and boolean results instead of just XML nodes.

If the query to find the node is too difficult, you can of course use text functions instead. For example use Text.FindBetween and Text.DecodeFromXML.

Examples

Query the Hello World text:

MBS( "XML.Query"; "<hello>Hello World</hello>"; "/hello/text()" )

Example result: Hello World

Query an attribute of a XML Node:

MBS("XML.Query"; "<OrderRequestHeader orderID=\"1629\" orderDate=\"2013-07-26T12:20:27\" type=\"new\"><Money>123.00</Money></OrderRequestHeader>"; "/OrderRequestHeader/@orderID" )

Example result:
<?xml version="1.0" encoding="UTF-8"?>
orderID="1629"

Query an attribute of a XML Node as string:

MBS("XML.Query"; "<OrderRequestHeader orderID=\"1629\" orderDate=\"2013-07-26T12:20:27\" type=\"new\"><Money>123.00</Money></OrderRequestHeader>"; "string(/OrderRequestHeader/@orderID)" )

Example result: 1629

Query all text from all nodes named reference ignoring namespaces:

MBS( "XML.Query"; XML Query::XML; "//*[local-name()='reference']/text()"; ""; 2 )

Finds a Field node where attribute name is "Class":

MBS( "XML.Query"; $xml; "/CDETS/Defect/Field[@name='Class']/text()")

Finds second companyname node in xml data with namespace invoice:

MBS("XML.Query"; XML Query::XML; "//invoice:companyname[2]"; "invoice=http://www.forum-datenaustausch.ch/invoice"; 2)

Query node without namespaces:

MBS( "XML.Query"; "<cfdi:Invoice invoiceTotal=\"450.24\"> </cfdi:Invoice>" ; "/Invoice/@invoiceTotal"; ""; 8+2)

Example result: 450.24

See also

Example Databases


XML.Parse   -   XML.ReadContainer

Feedback: Report problem or ask question.




Links
MBS FileMaker blog