SAX/DOM IDL -> C++ Mapping / Confused

Glenn R. Kronschnabl grk at
Thu Feb 12 20:37:59 GMT 1998


I was trying to duplicate the SAX/DOM java stuff in C++ (and interface with 
SP).  Now, I am a IDL newbie, but according the DOM spec, Node is defined to 
be just an interface.  In the SAXDOM code that's straightforward since java 
understands interfaces.  HOWEVER, in C++, according to the IDL -> C++ mapping, 
an interface is supposed to be constructed as a ABSTRACT base class using pure 
virtual functions.  The problem is when I try to enumerate over them, I get a 
'can't cast up from a virtual base class' error.  Here is abbreviated source.  
Obviously, I am making a fundamental mistake.  Can some kind person out there 
clue me in?  Thanks.

grk$ g++ In function `int main()': cannot cast up from virtual baseclass `Node'

----- cut here ---
#include <list>
#include <string>

class NodeList;
class NodeEnumerator;

class Node {
  enum NodeType {DOCUMENT, ELEMENT};
  virtual NodeType getNodeType() = 0;
  virtual Node* getParentNode() = 0;
  virtual NodeList* getChildren() = 0;

class Element : public virtual Node {
  virtual string getTagName() = 0;
  virtual NodeEnumerator* getElementsByTagName() = 0;

class SaxNode : public virtual Node {
   NodeType type;
   Node* parent;
   NodeList* children;

  virtual NodeType getNodeType() { return type; }
  virtual Node* getParentNode() { return parent; }
  virtual NodeList* getChildren() { return children; }

class SaxElement : public virtual Node, public Element, public SaxNode {
  string tagName;
  virtual NodeEnumerator* getElementsByTagName() { }
  virtual string getTagName() { return string("SaxElement"); }

class NodeList {
  virtual NodeEnumerator* getEnumerator() = 0;

class SaxNodeEnumerator;

class SaxNodeList: public list<SaxNode*>, public NodeList {
  virtual NodeEnumerator* getEnumerator() { }

class NodeEnumerator {
  virtual Node* getFirst() = 0;

class SaxNodeEnumerator : public NodeEnumerator {
  Node* getFirst() { }


  SaxElement se;

  SaxNodeList* list = (SaxNodeList*) se.getChildren();

  SaxNodeList::iterator snode = list->begin();

  for (; snode != list->end(); ++snode)

    SaxElement* elem = (SaxElement*) (*snode);


    SaxNodeEnumerator* e2 = (SaxNodeEnumerator*) elem->getElementsByTagName();

    SaxNode* s2 = (SaxNode*) e2->getFirst();

//    SaxNode snode = (SaxNode*) (*node);
//    cout << node->getNodeType() << endl;

--- cut here ----

Glenn R. Kronschnabl
Applied Research Laboratories        | grk at (PGP/MIME ok)
The University of Texas at Austin    |
PO Box 8029, Austin, TX 78713-8029   | (Ph) 512.835.3642 (FAX) 512.835.3808
10,000 Burnet Road, Austin, TX 78758 | ... but an Aggie at heart!

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at
Archived as:
To (un)subscribe, mailto:majordomo at the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at

More information about the Xml-dev mailing list