You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by Mark Weaver <ma...@npsl.co.uk> on 2004/04/07 14:26:30 UTC

rtree()->getNodesetRoot()

I've recently moved up to Xalan 1.7 and it seems that the getNodeSetRoot()
function has disappeared from XalanDocumentFragment.  This was used in one
of my (nasty) extension functions that implements a dictionary.

Basically, I'm trying to stick the RTF to a nodeset in the following code:

		dictionary_t::iterator it = m_dic.find(arg1->str().data());
		XPathExecutionContext::BorrowReturnMutableNodeRefList
theNodeList(executionContext);
		if (it != m_dic.end()) {
			theNodeList->addNode((*it).second->rtree().getNodesetRoot());
		}
		return executionContext.getXObjectFactory().createNodeSet(theNodeList);

the idea being that the nodeset is empty if the dictionary key could not be
found or contains the node otherwise.  (There's also a corresponding
function to return all of the nodes).

Could anyone advise as to the correct way to do this these days?

Thanks,

Mark


RE: rtree()->getNodesetRoot()

Posted by Mark Weaver <ma...@npsl.co.uk>.
> "Mark Weaver" <ma...@npsl.co.uk> wrote:
> > > However, if I understand you code correctly, the following is the
> > > equivalent of what you were doing before:
> > >
> > >    theNodeList->addNode(&(*it).second->rtree());
> > >
> > Unfortunately rtree() returns a const pointer, and addNode takes a
> non-const
> > pointer.
> 
> I think this is one of the cases where you are justified in using a
> const_cast.  
That seemed to do the trick, thanks very much!

Mark


RE: rtree()->getNodesetRoot()

Posted by da...@us.ibm.com.
Hi Mark,

"Mark Weaver" <ma...@npsl.co.uk> wrote:
> > However, if I understand you code correctly, the following is the
> > equivalent of what you were doing before:
> >
> >    theNodeList->addNode(&(*it).second->rtree());
> >
> Unfortunately rtree() returns a const pointer, and addNode takes a
non-const
> pointer.

I think this is one of the cases where you are justified in using a
const_cast.  The old code in getNodesetRoot() did that for the same reason
you need to.  The reason, if you're interested, is the history of Xalan-C
and its origins in Java.  One great thing I'd like to do in a 2.0 version
is to make the interfaces const throughout, which would solve these
inconsistencies.  On the other hand, the DOM interfaces really don't talk
about const, since the concept is language specific, so we'ed probably need
to extend or re-write the XalanDOM classes, so maybe it's not such a good
idea after all.

You could also do something like getting the first child of the
XalanDocumentFragment instance, then calling getParentNode(), which should
yield the exact same pointer, only it will be a non-const copy of the
pointer:

   const XalanDocumentFragment&  rtree = (*it).second->rtree();
   XalanNode* const  firstChild = rtree.getFirstChild();
   assert(firstChild != 0);
   XalanNode* const  parent = firstChild->getParentNode();
   assert(parent == &rtree);

> > The node set doesn't own any of the nodes and won't clean them up
> > when it's
> > destroyed.
> >
> Presumably then, clone is wrong because the clone won't be cleaned up?
In
> that case, I'm kind of stuck!

Cloning is not supported, nor is it needed.  Copying entire result tree
because our interfaces are not completely const correct is really
inefficient.

Hope that helps!

Dave


RE: rtree()->getNodesetRoot()

Posted by Mark Weaver <ma...@npsl.co.uk>.
> However, if I understand you code correctly, the following is the
> equivalent of what you were doing before:
>
>    theNodeList->addNode(&(*it).second->rtree());
>
Unfortunately rtree() returns a const pointer, and addNode takes a non-const
pointer.

> The node set doesn't own any of the nodes and won't clean them up
> when it's
> destroyed.
>
Presumably then, clone is wrong because the clone won't be cleaned up?  In
that case, I'm kind of stuck!

> Thanks!
>
> Dave
>
>
>
> |---------+--------------------------->
> |         |           "Mark Weaver"   |
> |         |           <mark@npsl.co.uk|
> |         |           >               |
> |         |                           |
> |         |           04/08/2004 04:33|
> |         |           AM              |
> |         |           Please respond  |
> |         |           to xalan-c-users|
> |---------+--------------------------->
>
> >-----------------------------------------------------------------
> ---------------------------------------------------------|
>   |
>                                                            |
>   |        To:      <xa...@xml.apache.org>
>                                                            |
>   |        cc:      (bcc: David N Bertoni/Cambridge/IBM)
>                                                            |
>   |        Subject: RE: rtree()->getNodesetRoot()
>                                                            |
>
> >-----------------------------------------------------------------
> ---------------------------------------------------------|
>
>
>
> > It disappeared becaue the "shadow" root document fragment disappeared,
> > which was a quick-and-hacked implementation and caused no end
> of trouble.
> >
> > Our ResultTreeFrag specialization of XalanDocumentFragment also
> > disappeared, as it was offering no value and just created complications.
> >
> > The real "root" is now the result tree fragment itself.  Is there any
> > reason why that won't work?
> >
> I'm just not sure how I add this to a nodeset.  Do I have to clone it?
>
> theNodeList->addNode((*it).second->rtree().cloneNode( false ));
>
> Should the deep flag be set? Does the nodelist then own (and therefore
> ultimately cleanup) the cloned tree?
>
> Thanks,
>
> Mark
>
>
> > Dave
> >
> >
> >
> > |---------+--------------------------->
> > |         |           "Mark Weaver"   |
> > |         |           <mark@npsl.co.uk|
> > |         |           >               |
> > |         |                           |
> > |         |           04/07/2004 05:26|
> > |         |           AM              |
> > |         |           Please respond  |
> > |         |           to xalan-c-users|
> > |---------+--------------------------->
> >
> > >-----------------------------------------------------------------
> > ---------------------------------------------------------|
> >   |
> >                                                            |
> >   |        To:      "Xalan-C-Users"
> > <xa...@xml.apache.org>
> >                        |
> >   |        cc:      (bcc: David N Bertoni/Cambridge/IBM)
> >                                                            |
> >   |        Subject: rtree()->getNodesetRoot()
> >                                                            |
> >
> > >-----------------------------------------------------------------
> > ---------------------------------------------------------|
> >
> >
> >
> > I've recently moved up to Xalan 1.7 and it seems that the
> getNodeSetRoot()
> > function has disappeared from XalanDocumentFragment.  This was used in
> one
> > of my (nasty) extension functions that implements a dictionary.
> >
> > Basically, I'm trying to stick the RTF to a nodeset in the following
> code:
> >
> >                          dictionary_t::iterator it =
> > m_dic.find(arg1->str().data());
> >
> > XPathExecutionContext::BorrowReturnMutableNodeRefList
> > theNodeList(executionContext);
> >                          if (it != m_dic.end()) {
> >
> > theNodeList->addNode((*it).second->rtree().getNodesetRoot());
> >                          }
> >                          return
> > executionContext.getXObjectFactory().createNodeSet(theNodeList);
> >
> > the idea being that the nodeset is empty if the dictionary key
> > could not be
> > found or contains the node otherwise.  (There's also a corresponding
> > function to return all of the nodes).
> >
> > Could anyone advise as to the correct way to do this these days?
> >
> > Thanks,
> >
> > Mark
> >
> >
> >
> >
> >
>
>
>
>
>


RE: rtree()->getNodesetRoot()

Posted by da...@us.ibm.com.
Hi Mark,

No, you don't need to clone anything.  If you're trying to turn the entire
result tree fragment into a node-set, you can take a look at what's going
on in the node-set extension function.  The source file is
xml-xalan/c/src/xalanc/XalanExtensions/FunctionNodeSet.cpp.

However, if I understand you code correctly, the following is the
equivalent of what you were doing before:

   theNodeList->addNode(&(*it).second->rtree());

The node set doesn't own any of the nodes and won't clean them up when it's
destroyed.

Thanks!

Dave



|---------+--------------------------->
|         |           "Mark Weaver"   |
|         |           <mark@npsl.co.uk|
|         |           >               |
|         |                           |
|         |           04/08/2004 04:33|
|         |           AM              |
|         |           Please respond  |
|         |           to xalan-c-users|
|---------+--------------------------->
  >--------------------------------------------------------------------------------------------------------------------------|
  |                                                                                                                          |
  |        To:      <xa...@xml.apache.org>                                                                           |
  |        cc:      (bcc: David N Bertoni/Cambridge/IBM)                                                                     |
  |        Subject: RE: rtree()->getNodesetRoot()                                                                            |
  >--------------------------------------------------------------------------------------------------------------------------|



> It disappeared becaue the "shadow" root document fragment disappeared,
> which was a quick-and-hacked implementation and caused no end of trouble.
>
> Our ResultTreeFrag specialization of XalanDocumentFragment also
> disappeared, as it was offering no value and just created complications.
>
> The real "root" is now the result tree fragment itself.  Is there any
> reason why that won't work?
>
I'm just not sure how I add this to a nodeset.  Do I have to clone it?

theNodeList->addNode((*it).second->rtree().cloneNode( false ));

Should the deep flag be set? Does the nodelist then own (and therefore
ultimately cleanup) the cloned tree?

Thanks,

Mark


> Dave
>
>
>
> |---------+--------------------------->
> |         |           "Mark Weaver"   |
> |         |           <mark@npsl.co.uk|
> |         |           >               |
> |         |                           |
> |         |           04/07/2004 05:26|
> |         |           AM              |
> |         |           Please respond  |
> |         |           to xalan-c-users|
> |---------+--------------------------->
>
> >-----------------------------------------------------------------
> ---------------------------------------------------------|
>   |
>                                                            |
>   |        To:      "Xalan-C-Users"
> <xa...@xml.apache.org>
>                        |
>   |        cc:      (bcc: David N Bertoni/Cambridge/IBM)
>                                                            |
>   |        Subject: rtree()->getNodesetRoot()
>                                                            |
>
> >-----------------------------------------------------------------
> ---------------------------------------------------------|
>
>
>
> I've recently moved up to Xalan 1.7 and it seems that the
getNodeSetRoot()
> function has disappeared from XalanDocumentFragment.  This was used in
one
> of my (nasty) extension functions that implements a dictionary.
>
> Basically, I'm trying to stick the RTF to a nodeset in the following
code:
>
>                          dictionary_t::iterator it =
> m_dic.find(arg1->str().data());
>
> XPathExecutionContext::BorrowReturnMutableNodeRefList
> theNodeList(executionContext);
>                          if (it != m_dic.end()) {
>
> theNodeList->addNode((*it).second->rtree().getNodesetRoot());
>                          }
>                          return
> executionContext.getXObjectFactory().createNodeSet(theNodeList);
>
> the idea being that the nodeset is empty if the dictionary key
> could not be
> found or contains the node otherwise.  (There's also a corresponding
> function to return all of the nodes).
>
> Could anyone advise as to the correct way to do this these days?
>
> Thanks,
>
> Mark
>
>
>
>
>




RE: rtree()->getNodesetRoot()

Posted by Mark Weaver <ma...@npsl.co.uk>.
> It disappeared becaue the "shadow" root document fragment disappeared,
> which was a quick-and-hacked implementation and caused no end of trouble.
>
> Our ResultTreeFrag specialization of XalanDocumentFragment also
> disappeared, as it was offering no value and just created complications.
>
> The real "root" is now the result tree fragment itself.  Is there any
> reason why that won't work?
>
I'm just not sure how I add this to a nodeset.  Do I have to clone it?

theNodeList->addNode((*it).second->rtree().cloneNode( false ));

Should the deep flag be set? Does the nodelist then own (and therefore
ultimately cleanup) the cloned tree?

Thanks,

Mark


> Dave
>
>
>
> |---------+--------------------------->
> |         |           "Mark Weaver"   |
> |         |           <mark@npsl.co.uk|
> |         |           >               |
> |         |                           |
> |         |           04/07/2004 05:26|
> |         |           AM              |
> |         |           Please respond  |
> |         |           to xalan-c-users|
> |---------+--------------------------->
>
> >-----------------------------------------------------------------
> ---------------------------------------------------------|
>   |
>                                                            |
>   |        To:      "Xalan-C-Users"
> <xa...@xml.apache.org>
>                        |
>   |        cc:      (bcc: David N Bertoni/Cambridge/IBM)
>                                                            |
>   |        Subject: rtree()->getNodesetRoot()
>                                                            |
>
> >-----------------------------------------------------------------
> ---------------------------------------------------------|
>
>
>
> I've recently moved up to Xalan 1.7 and it seems that the getNodeSetRoot()
> function has disappeared from XalanDocumentFragment.  This was used in one
> of my (nasty) extension functions that implements a dictionary.
>
> Basically, I'm trying to stick the RTF to a nodeset in the following code:
>
>                          dictionary_t::iterator it =
> m_dic.find(arg1->str().data());
>
> XPathExecutionContext::BorrowReturnMutableNodeRefList
> theNodeList(executionContext);
>                          if (it != m_dic.end()) {
>
> theNodeList->addNode((*it).second->rtree().getNodesetRoot());
>                          }
>                          return
> executionContext.getXObjectFactory().createNodeSet(theNodeList);
>
> the idea being that the nodeset is empty if the dictionary key
> could not be
> found or contains the node otherwise.  (There's also a corresponding
> function to return all of the nodes).
>
> Could anyone advise as to the correct way to do this these days?
>
> Thanks,
>
> Mark
>
>
>
>
>


Re: rtree()->getNodesetRoot()

Posted by da...@us.ibm.com.
Hi Mark,

It disappeared becaue the "shadow" root document fragment disappeared,
which was a quick-and-hacked implementation and caused no end of trouble.
Our ResultTreeFrag specialization of XalanDocumentFragment also
disappeared, as it was offering no value and just created complications.

The real "root" is now the result tree fragment itself.  Is there any
reason why that won't work?

Dave



|---------+--------------------------->
|         |           "Mark Weaver"   |
|         |           <mark@npsl.co.uk|
|         |           >               |
|         |                           |
|         |           04/07/2004 05:26|
|         |           AM              |
|         |           Please respond  |
|         |           to xalan-c-users|
|---------+--------------------------->
  >--------------------------------------------------------------------------------------------------------------------------|
  |                                                                                                                          |
  |        To:      "Xalan-C-Users" <xa...@xml.apache.org>                                                           |
  |        cc:      (bcc: David N Bertoni/Cambridge/IBM)                                                                     |
  |        Subject: rtree()->getNodesetRoot()                                                                                |
  >--------------------------------------------------------------------------------------------------------------------------|



I've recently moved up to Xalan 1.7 and it seems that the getNodeSetRoot()
function has disappeared from XalanDocumentFragment.  This was used in one
of my (nasty) extension functions that implements a dictionary.

Basically, I'm trying to stick the RTF to a nodeset in the following code:

                         dictionary_t::iterator it =
m_dic.find(arg1->str().data());

XPathExecutionContext::BorrowReturnMutableNodeRefList
theNodeList(executionContext);
                         if (it != m_dic.end()) {

theNodeList->addNode((*it).second->rtree().getNodesetRoot());
                         }
                         return
executionContext.getXObjectFactory().createNodeSet(theNodeList);

the idea being that the nodeset is empty if the dictionary key could not be
found or contains the node otherwise.  (There's also a corresponding
function to return all of the nodes).

Could anyone advise as to the correct way to do this these days?

Thanks,

Mark