From: Hamish Mackenzie (hamish_at_[hidden])
Date: 2003-06-27 03:49:19
On Fri, 2003-06-27 at 09:09, Anthony Williams wrote:
> Stefan Seefeld <seefeld_at_[hidden]> writes:
> > Hamish Mackenzie wrote:
> > > dom::document doc;
> > > dom::document_ref doc2( doc.root().document() );
> > > assert( &doc2 == &doc );
> > > and...
> > > assert( doc2 == doc );
> > > Can be implemented but ideally it would compare all the nodes in the
> > > document.
> > well, that's different. Do you want to know whether both documents are
> > equal, or whether they are identical, i.e. whether both references point to
> > the same document ?
> > Hmm, just to check whether we are still talking about the same thing here:
> > do we agree that there can't be a 'node' type, i.e. just a
> > 'node_ref'/'node_ptr' ?
> You mean: have "node" as an abstract class, so you can't have any objects of
> that type, but you can have pointers and references? Sounds good.
> What's wrong with just having boost::shared_ptr<Document> and
> boost::shared_ptr<Node>, boost::shared_ptr<Element> ?
> You could have each node store a boost::weak_ptr<Element> pointing to its
> parent, which is converted to a boost::shared_ptr<Element> when you ask for
> it. That way, a child doesn't keep its parent alive (though parents should
> keep their children alive), but you can still traverse up the tree if you
> You could do the same for documents --- the document holds a shared_ptr to the
> root element, and so keeps the whole tree alive. Each element holds a weak_ptr
> to the document, so you can retrieve the document from it, but it doesn't keep
> it alive. Consequently, if you erase an element from the document, but you
> still have a pointer to it, then the element itself is OK, but it will then
> die when your pointer goes out of scope. Also, if the document goes out of
> scope, then your element is still OK, but is no longer associated with a
This sounds like a description of an implementation rather than the
interface. This implementation would not solve the problem "what is a
node when it is not part of document?".
Your implementation would be much easier to wrap than libxml2. You
could implement the same interface simply with...
typedef Document document;
typedef Node * node_ptr;
typedef Node & node_ref;
The problem when wrapping libxml2 is that the node is stored by libxml2
in its own xmlNode structure. You can't add methods to it like you
could if you wrote your own Node.
You could copy the libxml2 tree into your own structure but then you are
on your own when it comes to higher level things like xpath and xslt.
-- Hamish Mackenzie <hamish_at_[hidden]>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk