XML Handling types Methods

Methods used to work with XML.

This page discusses:

DataTreeNode.ToJSON()

Method used to convert DataTreeNode structure to JSON.

Signature

DataTreeNode.ToJSON() : String

ReturnType

String

Example

// Creates an HTTP client
let client (HTTPClient)
client = CreateHTTPClient()

// Defines URI
let iURI (String)
iURI = "..."

// Defines output buffer
let oBuffer (string)

// Defines output DataTreeNode
let oDTN (DataTreeNode)

// Example1: Performs a GET request
oBuffer = client.Get(iURI, oDTN)

// Converts DataTreeNode to JSON structure
let json (string)
json = oDTN.ToJSON()

DataTreeNode.ToXML()

Method used to convert DataTreeNode structure to XML.

Signature

DataTreeNode.ToXML() : String

ReturnType

String

Example

/ Creates an HTTP client
let client (HTTPClient)
client = CreateHTTPClient()

// Defines URI
let iURI (String)
iURI = "..."

// Defines output buffer
let oBuffer (string)

// Defines output DataTreeNode
let oDTN (DataTreeNode)

// Example1: Performs a GET request
oBuffer = client.Get(iURI, oDTN)

// Converts DataTreeNode to XML structure
let xml (string)
xml = oDTN.ToXML()

HTTPClient.AddRequestHeaders()

AddRequestHeaders lets you transfer additional header information with an HTTP Request. Multiple headers can be added by calling this function multiple times. It is the responsibility of the caller to verify the header's validity.

Signature

HTTPClient.AddRequestHeaders(iHeader : String)VoidType

Arguments

Name Input/Output Required? Type Comment
iHeader In String A request header.

Example

// Creates an HTTP client
let client (HTTPClient)
client = CreateHTTPClient()

// Defines URI
let iURI (String)
iURI = "..."

// Defines output buffer
let oBuffer (string)

// Defines output DataTreeNode
let oDTN (DataTreeNode)

//Add Headers for Request
client.AddRequestHeaders("Content-Language: en-US")
client.AddRequestHeaders("Cache-Control: no-cache")

// Example1: Performs a POST request
oBuffer = client.Post(iURI, "XML", "<myXML>", oDTN)

// Example2: Performs a POST request
oBuffer = client.Post(iURI, "XML", "<myXML>")

// Example3: Performs a POST request
oBuffer = client.Post(iURI)

// Checking if request return code is OK (rc = 0)
if (client.ReturnCode == 0)
{
// success
Notify("#", oBuffer)
} 
else
{
// failure
Notify("Request return code is #", client.ReturnCode)
}

HTTPClient.Create()

This method creates an HTTP Client that will be used to execute HTTP requests.

Signature

CreateHTTPClient(): HTTPClient

Arguments

Name Input/Output Required? Type Comment
client Out HTTPClient The created client.

ReturnType

String

Example

// Creates a new HTTP Client
let client (HTTPClient)
client = CreateHTTPClient()

HTTPClient.Delete()

Method used to delete the specified resource.

Signature

HTTPClient.Delete(iURI : String, oDataTreeNode : DataTreeNode]) : String

Arguments

Name Input/Output Required? Type Comment
iURI In String The URI user wants to make a request on.
oDataTreeNode In DataTreeNode Contains the answer of request as a DataTreeNode structure, only if answer is in XML or JSON format.

ReturnType

String

Example

// Creates an HTTP client
let client (HTTPClient)
client = CreateHTTPClient()

// Defines URI
let iURI (String)
iURI = "..."

// Defines output buffer
let oBuffer (string)

// Defines output DataTreeNode
let oDTN (DataTreeNode)

// Example1: Performs a DELETE request
oBuffer = client.Delete(iURI, oDTN)

// Example2: Performs a LINK request
oBuffer = client.Delete(iURI)

// Checking if request return code is OK (rc = 0)
if (client.ReturnCode == 0)
{
    // success
    Notify("#", oBuffer)
} 
else
{
    // failure
    Notify("Request return code is #", client.ReturnCode)
}

HTTPClient.Get()

Method that requests a representation of the specified resource. Requests using GET should only retrieve data.

Signature

HTTPClient.Get(iURI : String, oDataTreeNode : DataTreeNode]) : String

Arguments

Name Input/Output Required? Type Comment
iURI In String -
oDataTreeNode In DataTreeNode -

ReturnType

String

Example

// Creates an HTTP client
let client (HTTPClient)
client = CreateHTTPClient()

// Defines URI
let iURI (String)
iURI = "..."

// Defines output buffer
let oBuffer (string)

// Defines output DataTreeNode
let oDTN (DataTreeNode)

// Example1: Performs a GET request
oBuffer = client.Get(iURI, oDTN)

// Example2: Performs a LINK request
oBuffer = client.Get(iURI)

// Checking if request return code is OK (rc = 0)
if (client.ReturnCode == 0)
{
    // success
    Notify("#", oBuffer)
} 
else
{
    // failure
    Notify("Request return code is #", client.ReturnCode)
}

HTTPClient.Patch()

Method used to apply partial modifications to a resource.

Signature

HTTPClient.Patch(iURI : String, iContentType : String [, iToPatch : String, oDataTreeNode : DataTreeNode]) : String

Arguments

Name Input/Output Required? Type Comment
iURI In String The URI user wants to make a request on.
iContentType In String The type of content to be posted (HTML, TEXT, XML).
iToPatch In String Represents what you want to patch.
oDataTreeNode In DataTreeNode Contains the answer of request as a DataTreeNode structure, only if answer is in XML or JSON format.

ReturnType

String

Example

// Creates an HTTP client
let client (HTTPClient)
client = CreateHTTPClient()

// Defines URI
let iURI (String)
iURI = "..."

// Defines output buffer
let oBuffer (string)

// Defines output DataTreeNode
let oDTN (DataTreeNode)

// Example1: Performs a PATCH request
oBuffer = client.Patch(iURI, "XML", "<myXML>", oDTN)

// Example2: Performs a PATCH request
oBuffer = client.Patch(iURI, "XML", "<myXML>")

// Example3: Performs a PATCH request
oBuffer = client.Patch(iURI)

HTTPClient.Post()

Method used to submit an entity to the specified resource, often causing a change in state or side effects on the server.

Signature

HTTPClient.Post(iURI : String, iContentType : String [, iToPost : String, oDataTreeNode : DataTreeNode]) : String

Arguments

Name Input/Output Required? Type Comment
iURI In String The URI user wants to make a request on.
iContentType In String The type of content to be posted (HTML, TEXT, XML).
iToPost In String Represents what you want to post.
oDataTreeNode In DataTreeNode Contains the answer of request as a DataTreeNode structure, only if answer is in XML or JSON format.

ReturnType

String

Example

// Creates an HTTP client
let client (HTTPClient)
client = CreateHTTPClient()

// Defines URI
let iURI (String)
iURI = "..."

// Defines output buffer
let oBuffer (string)

// Defines output DataTreeNode
let oDTN (DataTreeNode)

// Example1: Performs a POST request
oBuffer = client.Post(iURI, "XML", "<myXML>", oDTN)

// Example2: Performs a POST request
oBuffer = client.Post(iURI, "XML", "<myXML>")

// Example3: Performs a POST request
oBuffer = client.Post(iURI)

HTTPClient.Put()

Method used to replace all current representations of the target resource with the request payload.

Signature

HTTPClient.Put(iURI : String, iContentType : String [, iToPut : String, oDataTreeNode : DataTreeNode]) : String

Arguments

Name Input/Output Required? Type Comment
iURI In String The URI the user wants to make a request on.
iContentType In String The type of content to be posted (HTML, TEXT, XML).
iToPut In String Represents what you want to put.
oDataTreeNode In DataTreeNode Contains the answer of request as a DataTreeNode structure, only if answer is in XML or JSON format.

ReturnType

String

Example

// Creates an HTTP client
let client (HTTPClient)
client = CreateHTTPClient()

// Defines URI
let iURI (String)
iURI = "..."

// Defines output buffer
let oBuffer (string)

// Defines output DataTreeNode
let oDTN (DataTreeNode)

// Example1: Performs a PUT request
oBuffer = client.Put(iURI, "XML", "<myXML>", oDTN)

// Example2: Performs a PUT request
oBuffer = client.Put(iURI, "XML", "<myXML>")

// Example3: Performs a PUT request
oBuffer = client.Put(iURI)

JSONDocument.Save()

The Save method propagates the current changes in the JSONDocument to its persistent equivalent. This will modify the file on disk for file-based JSONDocuments or modify the Engineering Document for database documents.

Signature

JSONDocument.Save()

Example

// Creates JSON Document
let jsonDoc(jsonDocument)
jsonDoc = CreateJSONDocument("F:\json_doc_volatile.json")
// Check whether the document is empty or not
if jsonDoc <> NULL
{
        // notifying the user with a valid message
        Message("Json Doc Created)
        jsonDoc.Save()
}
else
       Message("Json Doc Not Created)

JSONNode.Parse()

The Parse Function is used to parse a string into a JSON Object.

Signature

JSONNode.Parse(iJSONString : String) : String

Arguments

Name Input/Output Required? Type Comment
String Out String Output JSON object as a string.
iJSONString In String JSON Node(Volatile Instance), JsonObject(String).
iJSONNode Out JSONNode Data structure where converted string is saved.

ReturnType

String

Example

// Creates a JSON Node
let jnode(JSONNode)
jnode = new("JSONNode","RootInstance",NULL)

if jnode <> NULL
{
	let str(String) 
str = "{'First_Name': 'Alex', 'Contact_number': [123,234,345], 'Hobies': {'indoor': 'Board_games', 'outdoor': 'Basket_ball'}}"

// Parse the string to convert into JSON object
jnode.Parse(str)
}

JSONNode.Stringify()

The STRINGIFY method converts a JSONNode data to a JSON formatted EKL string. This function is used to display the object in an easy format.

Signature

JSONNode.Stringify() : String

Arguments

Name Input/Output Required? Type Comment
String Out String Output JSON object as a string.

ReturnType

String

Example

// Creates JSON Document
let jsonDoc(jsonDocument)
jsonDoc = CreateJSONDocument("F:\json_doc_volatile.json")

// Check whether the document is empty or not
if jsonDoc <> NULL
{
        // Creates a JSON Node
        let jnode(JSONNode)
        set jnode = jsonDoc.Root 

       // Creates a variable of type string 
        let strings(String)
        strings = jnode.Stringify()
}

XMLDocument.Save()

Enables you to switch from the XML document back to the file. You can save the file on disk or modify the file in session and save the changes.

Signature

XMLDocument.Save()

XMLNode.GetDocument()

Enables you to retrieve the XML document.

Signature

XMLNode.GetDocument() : XMLDocument

ReturnType

XMLDocument

XMLNode.XPathQuery()

This function is used to find the required nodes from an XML file.

Signature

XMLNode.XPathQuery(XPath : String) : List

Arguments

Name Input/Output Required? Type Comment
iXPath In String XPath for the required node.

ReturnType

List

EKL Sample

let rootNode (XMLNode)
let xmlDoc(XMLDocument)
let requiredNodesList1(List)
let requiredNodesList2(List)
let requiredNodesList3(List)
let requiredNodesList4(List)
let requiredNodesList5(List)

/* Loading the pre existing XML Document from drive. */
xmlDoc = CreateXMLDocument("E:\\TestCase.xml")

if xmlReferenceDoc <> NULL
{
	/* Initializing Data */
	rootNode  = xmlDoc.Root
	requiredNodesList1 = rootNode->XPathQuery ("//Book/title")
requiredNodesList2= rootNode->XPathQuery ("//Book[@category='children']")
requiredNodesList3 = rootNode->XPathQuery ("//Book/title[@value='XQuery Kick Start']/../author")
requiredNodesList4 = rootNode->XPathQuery ("//Book[price=25.99]/title")
requiredNodesList5 = rootNode->XPathQuery ("//Book[year>2004]/price")
}