Document Class Methods

In this section, the Document class methods are presented in alphabetical order.

Syntax

GenJsonString()

Description

Use the GenJsonString method to generate a JSON (JavaScript Object Notation) structure from the Document object.

Parameters

None.

Returns

A String value.

Example

Local Document &DOC;
Local string &JSONdata;

&JSONdata = &DOC.GenJsonString();
&b_ret = &DOC.ParseJsonString(&JSONdata, False);

Syntax

GenXmlString([validate])

Description

Use this method to generate an XML string representing the logical document populated with data.

Note: The Generate button on the Document Tester page uses this method to generate a test XML document.

Parameters

Field or Control

Definition

validate

Specifies a Boolean value indicating whether to validate the XML document before it is generated.

Returns

An XML string.

Syntax

GetDocumentKey()

Description

Use this method to generate the document keys for the document as a DocumentKey object.

Parameters

None.

Returns

A DocumentKey object.

Example

Local Document &Doc;

&Doc = CreateDocument("Purchasing", "PurchaseOrder", "v1");
&DocKey = &Doc.GetDocumentKey();

Syntax

GetElement(ElementName)

Description

Use this method to retrieve a document element by name. The object returned will be a Collection, Compound, or Primitive object.

Note: Use the object’s ElementType property to determine which object type is returned.

Parameters

Field or Control

Definition

ElementName

Specifies the name of the document element as a string.

Returns

A Collection object, a Compound object, or a Primitive object.

Example

&Doc = CreateDocument(&DocKey);
&DocElem = &Doc.GetElement("BillTo");

Evaluate &DocElem.ElementType

When = %Document_Compound
   ...

When = %Document_Collection
   ...

When = %Document_Primitive
   ...

When-Other
   Error ...

End-Evaluate;

Syntax

GetRowset()

Description

Use this method to generate a standalone rowset for a relational-formatted document. The structure of the rowset matches the structure of the record mapped to the document. If the document is populated with data when GetRowset is called, then the rowset is populated with that data; otherwise, the rowset is empty.

Parameters

None.

Returns

A Rowset object.

Example

Local Document &Doc;
Local Rowset &Doc_RS;

&Doc = CreateDocument(&DocKey);
&Doc_RS = &Doc.GetRowset();

Syntax

GetSchema()

Description

Use this method to generate the XML schema definition for the document.

Parameters

None.

Returns

A string containing the XML schema definition.

Example

Local Document &Doc;
Local DocumentKey &DocKey;

&DocKey = CreateDocumentKey("Purchasing", "PurchaseOrder", "v1");
&Doc = CreateDocument(&DocKey);
&str = &Doc.GetSchema();

Syntax

ParseJsonString(JSON_data[, validate])

Description

Use the ParseJsonString method to generate a document from the JSON data provided as string.

Parameters

Field or Control

Definition

JSON_data

Specifies the JSON data as a string.

validate

Specifies a Boolean value indicating whether to validate the JSON data based on the XML schema.

Returns

A Boolean value: True if a document (or a valid document) was generated, False otherwise.

Example

Local Document &DOC;
Local string &JSONdata;

&string = &DOC.GenJsonString();
&b_ret = &DOC.ParseJsonString(&JSONdata, True);

Syntax

ParseXmlFromFile(file_name [, validate])

Description

Use this method to generate a document from the XML schema definition provided in a file.

Parameters

Field or Control

Definition

file_name

Specifies the name of the file as a string.

validate

Specifies a Boolean value indicating whether to validate the XML document as it is generated.

Returns

A Boolean value: True if a document (or a valid document) was generated, False otherwise.

Syntax

ParseXmlFromURL(URL [, validate])

Description

Use this method to generate a document from the XML schema definition provided at the specified URL.

Parameters

Field or Control

Definition

URL

Specifies the URL as a string.

validate

Specifies a Boolean value indicating whether to validate the XML document as it is generated.

Returns

A Boolean value: True if a document (or a valid document) was generated, False otherwise.

Syntax

ParseXmlString(XML_string [, validate])

Description

Use this method to generate a document from the XML schema definition provided as an XML string.

Parameters

Field or Control

Definition

XML_string

Specifies the XML as a string.

validate

Specifies a Boolean value indicating whether to validate the XML document as it is generated.

Returns

A Boolean value: True if a document (or a valid document) was generated, False otherwise.

Syntax

UpdateFromRowset(&Doc_RS)

Description

Use this method to update the document data with data from a stand-alone rowset.

Important! Any existing data in the document is erased and replaced by the data from the rowset.

Parameters

Field or Control

Definition

&Doc_RS

Specifies the stand-alone rowset as a Rowset object.

Returns

A Boolean value: True if the update was successful, False otherwise.

Syntax

ValidateData()

Description

Use this method to validate the data in a document.

Parameters

None.

Returns

A Boolean value: True if the document data is valid, False otherwise.