XML.CreateXML Method

Applies to TestComplete 15.70, last modified on December 17, 2024

Description

Use the CreateXML method to create a new instance of the XMLCheckpoint object.

Declaration

XML.CreateXML(Name, Document, Options)

Name [in]    Required    String    
Document [in]    Required    An IXMLDOMDocument object    
Options [in]    Optional    An XMLCheckpointOptions object    
Result Boolean

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

Name

Specifies the name of the element to be created.

To check whether the XML collection already has an element with the desired name, use the XML.Contains method.

Document

An object implementing the IXMLDOMDocument interface.

For information on methods and properties of the IXMLDOMDocument interface and about DOM, see the XML Core Services and Document Object Model article in the MSDN library.

Options

An XMLCheckpointOptions object that determines the options of a newly created XML checkpoint. To create an instance of the XMLCheckpointOptions object use the XML.CreateCheckpointOptions method.

If this parameter is omitted, the created XML checkpoint will have all the comparison settings disabled.

Result Value

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

Example

The following example demonstrates how you can use the CreateXML method to create a new XML checkpoint.

JavaScript

function CreateXMLDemo()
{

  var XMLDoc;

  // Checks if NewXMLCheckpoint already exists in the Stores | XML collection.
  if (! XML.Contains("NewXMLCheckpoint"))
    {
    // Creates an IXMLDOMDocument object
    // If you have MSXML 4:
    XMLDoc = getActiveXObject("Msxml2.DOMDocument.4.0");
    // If you have MSXML 6:
    XMLDoc = getActiveXObject("Msxml2.DOMDocument.6.0");

    XMLDoc.async = false;
    // Loads data form the XML file to the IXMLDOMDocument object.
    XMLDoc.load("D:\\Work Folder\\SampleXMLFile.xml");

    // Creates NewXMLCheckpoint and checks if the creation is successful.
    if (XML.CreateXML("NewXMLCheckpoint", XMLDoc))
      Log.Message("NewXMLCheckpoint has been successfully created.")
    else
      Log.Error("Failed to create NewXMLCheckpoint.")
    }
  else
    // If the checkpoint already exists, posts an error message to the log.
    Log.Error("The NewXMLCheckpoint already exists in the Stores | XML collection.");

}

JScript

function CreateXMLDemo()
{

  var XMLDoc;

  // Checks if NewXMLCheckpoint already exists in the Stores | XML collection.
  if (! XML.Contains("NewXMLCheckpoint"))
    {
    // Creates an IXMLDOMDocument object
    // If you have MSXML 4:
    XMLDoc = Sys.OleObject("Msxml2.DOMDocument.4.0");
    // If you have MSXML 6:
    XMLDoc = Sys.OleObject("Msxml2.DOMDocument.6.0");

    XMLDoc.async = false;
    // Loads data form the XML file to the IXMLDOMDocument object.
    XMLDoc.load("D:\\Work Folder\\SampleXMLFile.xml");

    // Creates NewXMLCheckpoint and checks if the creation is successful.
    if (XML.CreateXML("NewXMLCheckpoint", XMLDoc))
      Log.Message("NewXMLCheckpoint has been successfully created.")
    else
      Log.Error("Failed to create NewXMLCheckpoint.")
    }
  else
    // If the checkpoint already exists, posts an error message to the log.
    Log.Error("The NewXMLCheckpoint already exists in the Stores | XML collection.");

}

Python

def CreateXMLDemo():
  # Checks if NewXMLCheckpoint already exists in the Stores | XML collection. 
  if not XML.Contains("NewXMLCheckpoint"):
    # Creates an IXMLDOMDocument object. 
    # If you have MSXML 4:  
    # XMLDoc = Sys.OleObject["Msxml2.DOMDocument.4.0"]
    # If you have MSXML 6:  
    XMLDoc = Sys.OleObject["Msxml2.DOMDocument.6.0"]
    XMLDoc.async = False
    # Loads data form the XML file to the IXMLDOMDocument object. 
    XMLDoc.load("D:\\Work Folder\\SampleXMLFile.xml")
    # Creates NewXMLCheckpoint and checks if the creation is successful. 
    if XML.CreateXML("NewXMLCheckpoint", XMLDoc):
      Log.Message("NewXMLCheckpoint has been successfully created.")
    else: 
      Log.Error("Failed to create NewXMLCheckpoint.")
  else:
    # If the checkpoint already exists, posts an error message to the log. 
    Log.Error("The NewXMLCheckpoint already exists in the Stores | XML collection.")

VBScript

Sub CreateXMLDemo
  Dim XMLDoc

  ' Checks if NewXMLCheckpoint already exists in the Stores | XML collection.
  If Not XML.Contains("NewXMLCheckpoint") Then
    ' Creates an IXMLDOMDocument object.
    ' If you have MSXML 4:
    Set XMLDoc = Sys.OleObject("Msxml2.DOMDocument.4.0")
    ' If you have MSXML 6:
    Set XMLDoc = Sys.OleObject("Msxml2.DOMDocument.6.0")

    XMLDoc.async = False
    ' Loads data form the XML file to the IXMLDOMDocument object.
    XMLDoc.load("D:\Work Folder\SampleXMLFile.xml")

    ' Creates NewXMLCheckpoint and checks if the creation is successful.
    If XML.CreateXML("NewXMLCheckpoint", XMLDoc) Then
      Log.Message("NewXMLCheckpoint has been successfully created.")
    Else
      Log.Error("Failed to create NewXMLCheckpoint.")
    End If
  Else
    ' If the checkpoint already exists, posts an error message to the log.
    Log.Error("The NewXMLCheckpoint already exists in the Stores | XML collection.")
  End If

End Sub

DelphiScript

procedure CreateXMLDemo();
var XMLDoc;

begin

  // Checks if NewXMLCheckpoint already exists in the Stores | XML collection.
  if not XML.Contains('NewXMLCheckpoint') then
    begin
    // Creates an IXMLDOMDocument object.
    // If you have MSXML 4:
    XMLDoc := Sys.OleObject('Msxml2.DOMDocument.4.0');
    // If you have MSXML 6:
    XMLDoc := Sys.OleObject('Msxml2.DOMDocument.6.0');

    XMLDoc.async := false;
    // Loads data form the XML file to the IXMLDOMDocument object.
    XMLDoc.load('D:\Work Folder\SampleXMLFile.xml');

    // Creates NewXMLCheckpoint and checks if the creation is successful.
    if XML.CreateXML('NewXMLCheckpoint', XMLDoc) then
      Log.Message('NewXMLCheckpoint has been successfully created.')
    else
      Log.Error('Failed to create NewXMLCheckpoint.');
    end
  else
    // If the checkpoint already exists, posts an error message to the log.
    Log.Error('The NewXMLCheckpoint already exists in the Stores | XML collection.');

end;

C++Script, C#Script

function CreateXMLDemo()
{

  var XMLDoc;

  // Checks if NewXMLCheckpoint already exists in the Stores | XML collection.
  if (! XML["Contains"] ("NewXMLCheckpoint"))
    {
    // Creates an IXMLDOMDocument object.
    // If you have MSXML 4:
    XMLDoc = Sys["OleObject"]("Msxml2.DOMDocument.4.0");
    // If you have MSXML 6:
    XMLDoc = Sys["OleObject"]("Msxml2.DOMDocument.6.0");

    XMLDoc["async"] = false;
    // Loads data form the XML file to the IXMLDOMDocument object.
    XMLDoc["load"] ("D:\\Work Folder\\SampleXMLFile.xml");

    // Creates NewXMLCheckpoint and checks if the creation is successful.
    if (XML["CreateXML"] ("NewXMLCheckpoint", XMLDoc))
      Log["Message"]("NewXMLCheckpoint has been successfully created.")
    else
      Log["Error"]("Failed to create NewXMLCheckpoint.")
    }
  else
    // If the checkpoint already exists, posts an error message to the log.
    Log["Error"]("The NewXMLCheckpoint already exists in the Stores | XML collection.");

}

See Also

About XML Checkpoints
Contains Method
CreateCheckpointOptions Method
XMLCheckpointOptions Object

Highlight search results