TapHome

Parsing functions

TapHome script parsing functions — PARSETEXT, PARSEJSON, and PARSEXML for extracting values from text, JSON, and XML data.

PARSETEXT

Returns part of input text, based on left and right search patterns

PARSETEXT( input, left_pattern, right_pattern)

Examples:

PARSETEXT(“Lorem ipsum dolor sit amet”, “ipsum”, “amet”) (Result is “dolor sit”)
PARSETEXT(“<temp>12.2</temp>”, “<temp>”, “</temp”) (Result is 12.2)
PARSETEXT(“<temp>12.2</temp>”, “<temp>”) (Result is 12.2)
PARSETEXT(“status:ok,error:none”, “status:”) (Result is “ok”)
PARSETEXT(“Lorem ipsum dolor sit amet”, “ipsum”) (Result is “dolor”)
PARSETEXT(“Lorem ipsum dolor sit amet”, “ipsum…sit”) (Result is “amet”)
PARSETEXT(“Lorem ipsum dolor sit amet consectetur adipiscing”, “ipsum…sit”, “adipiscing”) (Result is “amet consectetur”)

PARSEJSON

Returns value of element from json formatted string. Element is specified with json path.

PARSEJSON( json_string, json_path, ignore_error)

Examples:

With json =

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
{
  "firstName": "John",
  "lastName" : "doe",
  "age" : 26,
  "address"  : {
    "streetAddress": "naist street",
    "city"         : "Nara",
    "postalCode"   : "630-0192"
  }
}
PARSEJSON(json, “firstName”)			(Result is “John”)
PARSEJSON(json, “address.city”)		(Result is “Nara”)
PARSEJSON(json, “address.country”)		(error)
PARSEJSON(json, “address.country”, 0)		(error)
PARSEJSON(json, “address.city”, 1)		(Result is null)

PARSEXML

Returns value of element from xml string. Element is specified with xml path.

PARSEXML( xml_string, xml_path)

Examples:

With xml=

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<?xml version="1.0"?>
<catalog>
	<book id="bk101">
		<author>Gambardella, Matthew</author>
		<title>XML Developer's Guide</title>
		<genre>Computer</genre>
		<price>44.95</price>
		<publish_date>2000-10-01</publish_date>
		<description>An in-depth look at creating...</description>
	</book>
	<book id="bk102">
		<author>Ralls, Kim</author>
		<title>Midnight Rain</title>
		<genre>Fantasy</genre>
		<price>5.95</price>
		<publish_date>2000-12-16</publish_date>
		<description>A former architect battles…</description>
	</book>
</catalog>
PARSEXML(xml, "//catalog/book[1]/price") (Result is 44.95)
PARSEXML(xml, "//book[2]/title") (Result is "Midnight Rain")
PARSEXML(xml, "//book[1]/@id") (Result is "bk101")
PARSEXML(xml, "//catalog/magazine[1]/price") (Result is null)

If xml contains namespaces, you have to fully specify element names with namespace, eg. PARSEXML(xml, “//DIDL-Lite:container[dc:title=‘My Playlist’’]/DIDL-Lite:res”);