xmlNewDocument()

Starts the creation of a new document in memory and returns the document ID.

Synopsis

int xmlNewDocument();

Parameters

Parameter Description
-

Return value

Document ID.

If an error occurs, -1 will be returned.

Description

Starts the creation of a new document in memory and returns a document ID. This document ID will be passed in future XML calls. The ID is valid until a call of xmlCloseDocument().

The function call xmlCloseDocument() is imperative to free the allocated memory to prevent a memory leak.

Example

This example creates a new document in memory and adds nodes to the document. It also sets attributes,

sets a node value and prints the content of the document.

#uses "CtrlXml"
main()
{
  int docNum = xmlNewDocument();
  xmlAppendChild(docNum, -1, XML_COMMENT_NODE, "my fine new
  comment");
  int node = xmlAppendChild(docNum, -1, XML_ELEMENT_NODE, "first
  element");
 node = xmlAppendChild(docNum, node, XML_ELEMENT_NODE,
  "sub_element");
  xmlSetElementAttribute(docNum, node, "anAttribute", "a
  value");
  node = xmlAppendChild(docNum, node, XML_TEXT_NODE, "some
  text");
  xmlSetNodeValue(docNum, node, "The new value");
  DebugN(xmlDocumentToString(docNum));
}

Assignment

XML Control Extension

Availability

CTRL. In every script where the "CtrlXml" extension (#uses "CtrlXml") is used.