XML.Contains Method

Applies to TestComplete 14.30, last modified on November 21, 2019

Description

Use the Contains method to find out whether the Stores | XML collection contains an element with the specified name.

Declaration

XML.Contains(Name)

Name [in]    Required    String    
Result Boolean

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Name

Specifies the name of the element whose existence should be verified.

Result Value

True, if the element with the given name was found and False otherwise.

Example

The following example demonstrates how you can use the Contains method to check whether the Stores | XML collection contains the element with the specified name.

JavaScript, JScript

function ContainsDemo()
{

  var XMLDoc;
  // Checks if the Stores | XML collection contains MyXMLCheckpoint.
  if (! XML.Contains("MyXMLCheckpoint"))
    // If the checkpoint does not exist, posts an error message to the log.
    Log.Error("The MyXMLCheckpoint does not exist in the Stores | XML collection.")
  else
    {
    Log.Message("The Stores | XML collection contains the required MyXMLCheckpoint.");
    // Compares the MyXMLCheckpoint data with the external XML document's data.
    XML.MyXMLCheckpoint.Compare("D:\\Work Folder\\SampleXMLFile.xml");
    }

}

Python

def ContainsDemo():
  # Checks if the Stores | XML collection contains MyXMLCheckpoint.
  if not XML.Contains("MyXMLCheckpoint"):
    # If the checkpoint does not exist, posts an error message to the log.
    Log.Error("The MyXMLCheckpoint does not exist in the Stores | XML collection.")
  else:
    Log.Message("The Stores | XML collection contains the required MyXMLCheckpoint.")
    # Compares the MyXMLCheckpoint data with the external XML document's data.
    XML.MyXMLCheckpoint.Compare("D:\\Work Folder\\SampleXMLFile.xml")

VBScript

Sub ContainsDemo
  Dim XMLDoc

  ' Checks if the Stores | XML collection contains MyXMLCheckpoint.
  If Not XML.Contains("MyXMLCheckpoint") Then
    ' If the checkpoint does not exist, posts an error message to the log.
    Log.Error("The MyXMLCheckpoint does not exist in the Stores | XML collection.")
  Else
    Log.Message("The Stores | XML collection contains the required MyXMLCheckpoint.")
    ' Compares the MyXMLCheckpoint data with the external XML document's data.
    XML.MyXMLCheckpoint.Compare("D:\Work Folder\SampleXMLFile.xml")
  End If

End Sub

DelphiScript

procedure ContainsDemo();
var XMLDoc;
begin

  // Checks if the Stores | XML collection contains MyXMLCheckpoint.
  if not XML.Contains('MyXMLCheckpoint') then
    // If the checkpoint does not exist, posts an error message to the log.
    Log.Error('The MyXMLCheckpoint does not exist in the Stores | XML collection.')
  else
    begin
    Log.Message('The Stores | XML collection contains the required MyXMLCheckpoint.');
    // Compares the MyXMLCheckpoint data with the external XML document's data.
    XML.MyXMLCheckpoint.Compare('D:\Work Folder\SampleXMLFile.xml');
    end;

end;

C++Script, C#Script

function ContainsDemo()
{

  var XMLDoc;
  // Checks if the Stores | XML collection contains MyXMLCheckpoint.
  if (! XML["Contains"]("MyXMLCheckpoint"))
    // If the checkpoint does not exist, posts an error message to the log.
    Log["Error"]("The MyXMLCheckpoint does not exist in the Stores | XML collection.")
  else
    {
    Log["Message"]("The Stores | XML collection contains the required MyXMLCheckpoint.");
    // Compares the MyXMLCheckpoint data with the external XML document's data.
    XML["MyXMLCheckpoint"]["Compare"] ("D:\\Work Folder\\SampleXMLFile.xml");
    }

}

See Also

About XML Checkpoints
Stores

Highlight search results