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 Ramesh <as...@gmail.com> on 2004/12/04 03:27:40 UTC

Why zero nodeset?

Hi,
Xalan 1.8 & Xerces 2.5

///XML file
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<catalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">      
   <book>   
      <author x="10">Adams</author>
      <State>NC</State>
      <subbook>
      	<genre>Computer</genre>
      	<price>44.95</price>
      </subbook>
    </book>
    <secondAuthor>234</secondAuthor>
</catalog>
////

My XPath query is /catalog/book/child::*[@x]
evaluate() returns a NodeSet with 0 nodes in it.

I used "Visual XPath" and it returned 10.

Am I doing anything wrong?



Thanks
Ramesh  







-- 
~best~of~luck~
Ramesh Kumar

Re: Why zero nodeset?

Posted by Ramesh <as...@gmail.com>.
This code is close to psuedocode so L"" is missing.

Problem was XALAN_CPP_NAMESPACE::XPathEvaluator::initialize() was missing.
After adding this things started working.

I hardly know about relation b/w Xerces object & Xalan objects. I have
tried to read in newsgroups to get more info.


Pls let me know how I am complicating.



Thanks
Ramesh 





On Tue, 21 Dec 2004 09:12:40 -0800, david_n_bertoni@us.ibm.com
<da...@us.ibm.com> wrote:
> > SimpleXPathAPI  & my app are different.
> 
> Yes, but your's needn't be so different from the sample application.  You
> have modified things which you did not need to modify.
> 
> > Here is my sample code. Pls let me know if there is anything wrong.
> > I am using xerces parser because I need to read/edit/create the XML
> documents
> 
> > m_prefXalanDocument =
> > m_pXercesParserLiaison->createDocument(m_pDOMDocument,0,1);
> 
> m_prefXalanDocument = 
> m_pXercesParserLiaison->createDocument(m_pDOMDocument,true,true);
> 
> > m_pXalanContextNode =
> >
> m_pXPathEvaluator->selectSingleNode(*m_pXercesDOMSupport,m_prefXalanDocument,
> >  "/catalog/book".c_str(),*m_pXalanDocumentPrefixResolver);
> 
> What compiler are you using?  This code cannot possibly compile, unless
> your compiler is totally broken.
> 
> > m_pXObjectPtr = new
> >
> XALAN_CPP_NAMESPACE::XObjectPtr((m_pXPathEvaluator->evaluate(*m_pXercesDOMSupport,m_pXalanContextNode,
> > "child::*[@x]",*m_pXalanDocumentPrefixResolver)));
> 
> XObjectPtr is a reference-counting smart pointer.  You should never create
> one using new.
> 
> XObjectPtr  m_xobjectPtr =
>                m_pXPathEvaluator->evaluate(
>                    *m_pXercesDOMSupport,
>                    m_pXalanContextNode,
>                    "child::*[@x]",
>                    *m_pXalanDocumentPrefixResolver);
> 
> > prefXObject            =               m_pXObjectPtr->get();
> >
> 
> This is unnecessary.  XObjectPtr has an overloaded operator -> which
> returns a pointer to the underlying XObject instance.
> 
> > if(XObject::eObjectType::eTypeNodeSet          ==
> prefXObject->getType())
> > {
> >    NodeRefList                 pTemp(prefXObject->nodeset());
> >     iTempCount                 =               pTemp.getLength();
> >
> >     // iTempCount               is ZERO
> > }
> 
> Why are you making a copy of the NodeRefList?  Do you need to save it for
> some reason?
> 
> if(XObject::eObjectType::eTypeNodeSet == xobjectPtr->getType())
> {
>   const NodeRefListBase&        pTemp = prefXObject->nodeset();
>   iTempCount            =               pTemp.getLength();
> 
>  // iTempCount           is ZERO
> }
> 
> Without something that will compile, and lacking input data, no one can
> possible figure out why your code is not working.  If you want someone to
> help you, you need to provide a _minimal_ and _complete_ sample that
> illustrates the problem.
> 
> Dave
> 


-- 
~best~of~luck~
Ramesh Kumar

Re: Why zero nodeset?

Posted by da...@us.ibm.com.
> SimpleXPathAPI  & my app are different.

Yes, but your's needn't be so different from the sample application.  You 
have modified things which you did not need to modify.

> Here is my sample code. Pls let me know if there is anything wrong.
> I am using xerces parser because I need to read/edit/create the XML 
documents

> m_prefXalanDocument =
> m_pXercesParserLiaison->createDocument(m_pDOMDocument,0,1);

m_prefXalanDocument = 
m_pXercesParserLiaison->createDocument(m_pDOMDocument,true,true);

> m_pXalanContextNode =
> 
m_pXPathEvaluator->selectSingleNode(*m_pXercesDOMSupport,m_prefXalanDocument,
>  "/catalog/book".c_str(),*m_pXalanDocumentPrefixResolver);

What compiler are you using?  This code cannot possibly compile, unless 
your compiler is totally broken.

> m_pXObjectPtr = new
> 
XALAN_CPP_NAMESPACE::XObjectPtr((m_pXPathEvaluator->evaluate(*m_pXercesDOMSupport,m_pXalanContextNode,
> "child::*[@x]",*m_pXalanDocumentPrefixResolver)));

XObjectPtr is a reference-counting smart pointer.  You should never create 
one using new.

XObjectPtr  m_xobjectPtr =
                m_pXPathEvaluator->evaluate(
                    *m_pXercesDOMSupport,
                    m_pXalanContextNode,
                    "child::*[@x]",
                    *m_pXalanDocumentPrefixResolver);

> prefXObject            =               m_pXObjectPtr->get();
>

This is unnecessary.  XObjectPtr has an overloaded operator -> which 
returns a pointer to the underlying XObject instance.

> if(XObject::eObjectType::eTypeNodeSet          == 
prefXObject->getType())
> {
>    NodeRefList                 pTemp(prefXObject->nodeset());
>     iTempCount                 =               pTemp.getLength();
> 
>     // iTempCount               is ZERO
> }

Why are you making a copy of the NodeRefList?  Do you need to save it for 
some reason?

if(XObject::eObjectType::eTypeNodeSet == xobjectPtr->getType())
{
   const NodeRefListBase&        pTemp = prefXObject->nodeset();
   iTempCount            =               pTemp.getLength();

  // iTempCount           is ZERO
}

Without something that will compile, and lacking input data, no one can 
possible figure out why your code is not working.  If you want someone to 
help you, you need to provide a _minimal_ and _complete_ sample that 
illustrates the problem.

Dave

Re: Why zero nodeset?

Posted by Ramesh <as...@gmail.com>.
SimpleXPathAPI  & my app are different.
Here is my sample code. Pls let me know if there is anything wrong.
I am using xerces parser because I need to read/edit/create the XML documents

===================================================
XercesDOMParser*	m_pXercesDOMParser;
DOMDocument*        m_pDOMDocument;
XalanDocument*	m_prefXalanDocument;
XPathEvaluator*	m_pXPathEvaluator;
XercesDOMSupport*	m_pXercesDOMSupport;
XercesParserLiaison*	m_pXercesParserLiaison;
XalanDocumentPrefixResolver*	m_pXalanDocumentPrefixResolver;	
XercesDocumentWrapper*        	m_prefXercesDocumentWrapper;
XObject*			prefXObject      =	0;


m_pXmlFile	=	pFileName;
m_pXercesDOMParser =	new	xercesc::XercesDOMParser;
m_pXercesDOMParser->parse((const XMLCh*)m_pXmlFile.c_str());
m_pDOMDocument	=	m_pXercesDOMParser->getDocument();	


m_prefXalanDocument =
m_pXercesParserLiaison->createDocument(m_pDOMDocument,0,1);

	
m_pXalanDocumentPrefixResolver
=	new	XalanDocumentPrefixResolver(m_prefXalanDocument);

m_prefXercesDocumentWrapper=m_pXercesParserLiais->mapDocumentToWrapper(m_prefXalanDocument);


m_pXalanContextNode =
m_pXPathEvaluator->selectSingleNode(*m_pXercesDOMSupport,m_prefXalanDocument,
 "/catalog/book".c_str(),*m_pXalanDocumentPrefixResolver);


m_pXObjectPtr = new
XALAN_CPP_NAMESPACE::XObjectPtr((m_pXPathEvaluator->evaluate(	*m_pXercesDOMSupport,m_pXalanContextNode,
"child::*[@x]",	*m_pXalanDocumentPrefixResolver)));	


prefXObject	=	m_pXObjectPtr->get();

if(XObject::eObjectType::eTypeNodeSet	== prefXObject->getType())
{
   NodeRefList	pTemp(prefXObject->nodeset());
    iTempCount	=	pTemp.getLength();
    
    // iTempCount	 is ZERO
}	

===================================================

Thanks
Ramesh










On Sat, 4 Dec 2004 15:52:43 -0500, david_n_bertoni@us.ibm.com
<da...@us.ibm.com> wrote:
> > ///XML file
> > <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
> > <catalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> >    <book>
> >       <author x="10">Adams</author>
> >       <State>NC</State>
> >       <subbook>
> >                        <genre>Computer</genre>
> >                        <price>44.95</price>
> >       </subbook>
> >     </book>
> >     <secondAuthor>234</secondAuthor>
> > </catalog>
> > ////
> >
> > My XPath query is /catalog/book/child::*[@x]
> > evaluate() returns a NodeSet with 0 nodes in it.
> 
> I ran your document with the sample program SimpleXPathAPI that ships with
> Xalan-C, and it found one node using your document and XPath expression. I
> don't know why your code is failing, but you might want to compare it to
> the sample code.
> 
> >
> > I used "Visual XPath" and it returned 10.
> 
> If "Visual XPath" returned 10 nodes evaluating that XPath expression with
> the exact document you've supplied then it has a bug.  There are only 3
> child elements of "book", and there is only one with an attribute "x".
> 
> Dave
> 


-- 
~best~of~luck~
Ramesh Kumar

Re: Why zero nodeset?

Posted by da...@us.ibm.com.
> ///XML file
> <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
> <catalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
>    <book> 
>       <author x="10">Adams</author>
>       <State>NC</State>
>       <subbook>
>                        <genre>Computer</genre>
>                        <price>44.95</price>
>       </subbook>
>     </book>
>     <secondAuthor>234</secondAuthor>
> </catalog>
> ////
> 
> My XPath query is /catalog/book/child::*[@x]
> evaluate() returns a NodeSet with 0 nodes in it.

I ran your document with the sample program SimpleXPathAPI that ships with 
Xalan-C, and it found one node using your document and XPath expression. I 
don't know why your code is failing, but you might want to compare it to 
the sample code.

> 
> I used "Visual XPath" and it returned 10.

If "Visual XPath" returned 10 nodes evaluating that XPath expression with 
the exact document you've supplied then it has a bug.  There are only 3 
child elements of "book", and there is only one with an attribute "x".

Dave