xmlNodeType()

Returns the type of the given node.

Synopsis

int xmlNodeType(unsigned doc, unsigned node);

Parameters

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

Return value

Node type.

In case of a failure it returns -1.

Description

Returns the type of the given node.

The following node type constants are defined:

Constant
XML_ELEMENT_NODE
XML_ATTRIBUTE_NODE
XML_TEXT_NODE
XML_CDATA_SECTION_NODE
XML_ENTITY_REFERENCE_NODE
XML_ENTITY_NODE
XML_PROCESSING_INSTRUCTION_NODE
XML_COMMENT_NODE
XML_DOCUMENT_NODE
XML_DOCUMENT_TYPE_NODE
XML_DOCUMENT_FRAGMENT_NODE
XML_NOTATION_NODE

Example

Reads 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. XmlNextSibling is used to return the internal Id of the next sibling of a node. XmlNodeName returns the name of a node. XmlNodeType returns the type of the given node.

#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.