xmlNodeValue()

Returns the value of the given node.

Synopsis

string xmlNodeValue(unsigned doc, unsigned node);

Parameters

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

Return value

Node value

In case of a failure it returns -1.

Description

Returns the value of the given node.

The meaning of the value depends on the node type that is asked.

The following node type constants are here meaningful:

Constant Meaning
XML_ATTRIBUTE_NODE Attribute value
XML_CDATA_SECTION_NODE Content of the CDATA section
XML_COMMENT_NODE Comment
XML_PROCESSING_INSTRUCTION_NODE Data of the processing instruction
XML_TEXT_NODE Text

All the other node types do not have a node value and will return an empty string.

Example

#uses "CtrlXml"
main()
{
  unsigned doc;
  int ret;
  int rootId;
  int nodeType;
  int childId;
  string nodeTypeText;
  doc = xmlNewDocument();
  DebugN("doc", doc);
  rootId = xmlAppendChild(doc, -1, 1);
  //Node type definition
  nodeType = XML_ATTRIBUTE_NODE;
  nodeTypeText = "Attribute name";
  //Add child
  childId = xmlAppendChild(doc, rootId, nodeType,
  "name_"+nodeTypeText);
  DebugN("xmlAppendChild", nodeTypeText + "(" + nodeType + ")",
  childId);
  //Detect node type
  DebugN("xmlNodeType", childId, nodeTypeText+"("+nodeType+")",
  xmlNodeType(doc, childId));
  //Detect node name
  DebugN("xmlNodeName", childId, nodeTypeText+"("+nodeType+")",
  xmlNodeName(doc, childId));
  //Set value
  DebugN("xmlSetNodeValue", childId, xmlSetNodeValue(doc, childId,
  "Value_"+nodeTypeText));
  //Read value
  DebugN("Read node value: ", childId, xmlNodeValue(doc,
  childId));
  //Add attribute
  DebugN("xmlSetElementAttribute", childId,
  xmlSetElementAttribute(doc, childId, "attrib",
  "att_"+nodeTypeText));
  //Read attribute
  mapping m;
  m = xmlElementAttributes(doc, childId);
  DebugN("xmlSetElementAttribute", childId, m);
  //Write to string
  DebugN("xmlDocumentToString", xmlDocumentToString(doc));
  ret = xmlCloseDocument(doc);
  DebugN(ret);
}

Assignment

XML Control Extension

Availability

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