TapHome

Parsolási függvények

TapHome szkript parsoló függvények — PARSETEXT, PARSEJSON és PARSEXML értékek kinyeréséhez szövegből, JSON-ból és XML-ből.

PARSETEXT

A bevitt szövegből adott bal és jobb keresési minta alapján visszaad egy részletet.

PARSETEXT( input, left_pattern, right_pattern)

Példák:

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

Visszaadja egy elem értékét JSON formátumú stringből. Az elemet a json_path útvonal adja meg.

PARSEJSON( json_string, json_path, ignore_error)

Példák:

JSON példa:

 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

Visszaadja egy elem értékét XML stringből. Az elemet az xml_path útvonal adja meg.

PARSEXML( xml_string, xml_path)

Példák:

XML minta:

 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)

Ha az XML tartalmaz neve‑space‑eket, az elemek nevét teljes egészében, a namespace-szel együtt kell megadni, pl. PARSEXML(xml, “//DIDL-Lite:container[dc:title=‘My Playlist’’]/DIDL-Lite:res”);