Xml
Library of functions for XML data.
Functions
InferAndRead
Reads XML data from a location with schema detection (inference).
Xml.InferAndRead(location: location or string, sampleSize: optional int, encoding: optional string, preferNulls: optional bool)
Parameters
-
location
: The location or url of the data to read. -
sampleSize
: Specifies the number of objects to sample within nested lists.
If a large sampleSize
is used, the detection will take more time to complete,
but has a higher chance of detecting the correct format.
To force the detection to read the full data, set sampleSize
to -1.
encoding
: Specifies the encoding of the data.
If the encoding is not specified it is determined automatically.
preferNulls
: If set to true and during inference the system does read the whole data, marks all fields as nullable. Defaults to true.
Xml.InferAndRead("http://server/file.xml")
Parse
Parses XML data from a string.
Xml.Parse(string: string, type: type, timeFormat: optional string, dateFormat: optional string, timestampFormat: optional string)
Parameters
-
string
: The string containing the XML to parse. -
type
: The type of the data in the XML. -
timeFormat
: Specifies the format to parse time fields. Defaults to"HH:mm[:ss[.SSS]]"
. -
dateFormat
: Specifies the format to parse date fields. Defaults to"yyyy-M-d"
. -
timestampFormat
: Specifies the format to parse timestamp fields. Defaults to"yyyy-M-d['T'][ ]HH:mm[:ss[.SSS]]"
.
Returns
- The data parsed from the XML string.
let
dataType = type record(
person: collection(
record(name: string, age: int, salary: double)
)),
data = """
<document>
<person>
<name>john</name>
<age>34</age>
<salary>14.6</salary>
</person>
<person>
<name>jane</name>
<age>32</age>
<salary>15.8</salary>
</person>
<person>
<name>Bob</name>
<age>25</age>
<salary>12.9</salary>
</person>
</document>"""
in
Xml.Parse(data, dataType)
Read
Reads XML data from a location without schema detection.
Xml.Read(location: location or string, type: type, encoding: optional string, timeFormat: optional string, dateFormat: optional string, timestampFormat: optional string)
Parameters
-
location
: The location or url of the data to read. -
type
: The type of the data in the XML. -
encoding
: Specifies the encoding of the data. Defaults to "utf-8". -
timeFormat
: Specifies the format to parse time fields. Defaults to"HH:mm[:ss[.SSS]]"
. -
dateFormat
: Specifies the format to parse date fields. Defaults to"yyyy-M-d"
. -
timestampFormat
: Specifies the format to parse timestamp fields. Defaults to"yyyy-M-d['T'][ ]HH:mm[:ss[.SSS]]"
.
Returns
- The data read from the XML file.
let
fileType = type record(name: string, age: int, salary: double)
in
Xml.Read("http://server/person.xml", fileType)