Xport Interface: markup::parent
Returns a pointer to the parent element
of the called markup
object.
markup* markup::parent();1st Variety
const markup* markup::parent();2nd Variety
Parameters
None
Returns
Returns a pointer to the parent element
of the called markup object.
Remarks
This operation is used to obtain a pointer to the called markup object's parent. The returned pointer is always guaranteed to return a derived element
object, since only element
objects can contain other child markup objects.
All markup objects in the document tree have a parent element, except for the
document root. When called on the document root, this operation will return NULL.
Complexity
Constant
Example
#include "xhtml_doc.h"
#include <iostream>
int main(int argc, char* argv[])
{
using namespace Xport;
document doc(root_doc);
*doc.body() << comment("Sample xhtml document to test the markup_type() operation");
*doc.body() << procinstr("php include 'somedoc.htm'");
markup::iterator it = doc.body()->insert(element(ul));
*it << (element(li) << "List item 1");
*it << (element(li) << "List item 2");
*it << (element(li) << "List item 3");
formatter fmtr(std::cout);
doc.write(fmtr);
std::cout << "\n\n";
markup::const_descendant_iterator dit = doc.descendant_begin();
for (; dit != doc.descendant_end(); ++dit) {
switch (dit->markup_type())
{
case mt_doctype_declaration:
std::cout << "Doctype declaration";
break;
case mt_element:
std::cout << dit->tag_name() << " element";
break;
case mt_pcdata:
std::cout << "PCDATA";
break;
case mt_comment:
std::cout << "Comment";
break;
case mt_processing_instruction:
std::cout << "Processing instruction";
break;
default:
break;
}
const markup* pParent = dit->parent();
if (pParent) {
std::cout << " has for a parent, " << pParent->tag_name() << ".\n";
} else {
std::cout << " has no parent.\n";
}
}
return 0;
}