TapHome

Funkcje parsowania

Funkcje parsowania w skrypcie TapHome — PARSETEXT, PARSEJSON i PARSEXML do wyodrębniania wartości z tekstu, danych JSON i XML.

PARSETEXT

Zwraca część wejściowego tekstu na podstawie wzorców wyszukiwania po lewej i prawej stronie.

PARSETEXT( input, left_pattern, right_pattern)

Przykłady:

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

Zwraca wartość elementu z sformatowanego JSON w postaci string. Element określany jest ścieżką JSON.

PARSEJSON( json_string, json_path, ignore_error)

Przykłady:

Z 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

Zwraca wartość elementu z łańcucha XML. Element określany jest ścieżką XML.

PARSEXML( xml_string, xml_path)

Przykłady:

Z 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)

Jeśli XML zawiera przestrzenie nazw, należy w pełni określić nazwy elementów wraz z przestrzeniami, np. PARSEXML(xml, “//DIDL-Lite:container[dc:title=‘My Playlist’’]/DIDL-Lite:res”);