xmlNodeName()
Returns the name of a node.
Synopsis
string xmlNodeName(unsigned doc, unsigned node);
Parameters
Parameter | Description |
---|---|
doc | The document ID returned by e.g. xmlNewDocument(). |
node | Node ID |
Return value
Node ID
In case of a failure it returns -1.
Description
Returns the name of a node.
The meaning of the name depends on the type of node being asked. All given node type names are integer constants which are available in the CTRL script when the CtrlXml extension is used.
The following node type constants are defined:
Constant | Meaning |
---|---|
XML_ATTRIBUTE_NODE | Attribute name |
XML_CDATA_SECTION_NODE | String "#cdata-section" |
XML_COMMENT_NODE | String "#comment" |
XML_DOCUMENT_NODE | String "#document" |
XML_DOCUMENT_FRAGMENT_NODE | String "#document-fragment" |
XML_DOCUMENT_TYPE_NODE | Name of the document type |
XML_ELEMENT_NODE | Tag name |
XML_ENTITY_NODE | Name of the unit |
XML_ENTITY_REFERENCE_NODE | Name of the reference unit |
XML_NOTATION_NODE | Name of the alert |
XML_PROCESSING_INSTRUCTION_NODE | The target of the processing instruction |
XML_TEXT_NODE | String "#text" |
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.
#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
Availability
CTRL. In every script where the "CtrlXml" extension (#uses "CtrlXml") is used.