xmlFirstChild()

Returns an internal ID to the first child node in the DOM tree.

Synopsis

int xmlFirstChild(unsigned doc[, unsigned node]);

Parameters

Parameter Description
doc The document ID returned by e.g. xmlNewDocument().
node

Optional parameter.

The node whose child node ID will be returned. If the node argument is not given, it returns the root node of the tree.

Return value

If the node argument is not given, it returns the root node of the tree.

It returns -1 if this node does not exist.

Description

Returns an internal ID to the first child node in the DOM tree.

Example

This example eads the d:/XmlTest0.xml file and creates a document. The content of the document is printed using printNodes. The function xmlElementAttributes returns all node attributes as a mapping.

#uses "CtrlXml"
global uint docNum;
global string err;
global int errLine, errColumn;
main()
{
  uint node;
  DebugN(docNum = xmlDocumentFromFile("d:/XmlTest0.xml", err,
  errLine,
  errColumn));
  DebugN("error:", err, errLine, errColumn);
  printNodes(node = xmlFirstChild(docNum));
  xmlSetElementAttribute(docNum, node, "test_attribute", "some
  fancy
  value !!");
}
void printNodes(int node)
{
  if ( node != -1 )
  {
    if ( xmlNodeType(docNum, node) == XML_TEXT_NODE )
    DebugN("value:", xmlNodeValue(docNum, node));
    if ( xmlNodeType(docNum, node) == XML_ELEMENT_NODE )
    DebugN(xmlNodeName(docNum, node), xmlElementAttributes(docNum,
    node) );
    printNodes(xmlFirstChild(docNum, node));
    printNodes(xmlNextSibling(docNum, node));
    DebugN(xmlDocumentFromFile(docNum, "d:/XmlTest0.xml",err,
    errLine,
    errColumn));
  }
}

Assignment

XML Control Extension

Availability

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