xmlChildNodes()

Writes all child nodes of the given node into the nodes' reference parameter.

Synopsis

int xmlChildNodes( unsigned doc, unsigned node, dyn_uint &nodes);

Parameters

Parameter Description
doc The document ID returned by e.g. xmlNewDocument().
node Node ID
nodes Child nodes (return parameter)

Return value

0 if the writing process was successful.

If an error occurs, -1 will be returned.

Description

EXAMPLE

This example creates a document through xmlNewDocument() and adds nodes to the document through xmlAppendChild(). The nodes are printed using xmlChildNodes.

#uses "CtrlXml"
main()
{
  dyn_uint nodes;
  string nNameP, nName1,nName2, nName3, nName4, nName5;
  unsigned docNum = xmlNewDocument();
  //Create a new document
  xmlAppendChild(docNum, -1, XML_COMMENT_NODE, "my fine new
  comment");
  //Add a new node
  int node = xmlAppendChild(docNum, -1, XML_ELEMENT_NODE, "Parent
  node");
  //Add a new node
  nNameP = xmlNodeName(docNum, node);
  int PNode = xmlParentNode(docNum, node);
  DebugN("Parent node:", nNameP);
  xmlAppendChild(docNum,PNode, XML_ELEMENT_NODE, "First
  element");
  nName1 = xmlNodeName(docNum, node);
  DebugN("Node 1:", nName1);
  int node2 = xmlAppendChild(docNum, -1, XML_ELEMENT_NODE, "Second
  element");
  nName2 = xmlNodeName(docNum, node2);
  DebugN("Node 2:", nName2);
  int j = xmlSetElementAttribute(docNum, node2, "Attribute1",
  "Example Attribute");
  //Set a new attribute
  int node3 = xmlAppendChild(docNum, node2, XML_ELEMENT_NODE,
  "Third element");
  nName3 = xmlNodeName(docNum,node3);
  DebugN("Node 3:", nName3);
  int i = xmlSetNodeValue(docNum, nName2, "And a node value");
  //Set a new value
  int node4 = xmlAppendChild(docNum, -1, XML_ELEMENT_NODE, "Fourth
  element");
  nName4 = xmlNodeName(docNum, node4);
  DebugN("Node 4:", nName4);
  int node3 = xmlAppendChild(docNum, -1, XML_ELEMENT_NODE, "Fifth
  element");
  xmlSetElementAttribute(docNum, node3, "Attribute2", "A second
  example attribute");
  int k = xmlChildNodes(docNum, PNode, nodes);
  DebugN("xmlChildNodes successful:", k, "List of the nodes:",
  nodes);
  //Print the child nodes
}

Assignment

XML Control Extension

Availability

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