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 David Bertoni <db...@apache.org> on 2006/06/01 23:57:20 UTC

Re: MapNode problems

Antonio Scotti wrote:
> Hi! I've a problem using a XercesDocumentWrapper.
> 
> I've a Xerces DOMDocument and I'd like to evaluate an xpath expression 
> on a specific DOMElement.
> 
> What I've done is to build a XercesDOMWrapperParsedSource (using the 
> DOMElement, a XercesParserLiaison and a XercesDOMSupport).
> 
> Then I got a XercesDocumentWrapper from the XercesParserLiaison (using 
> mapDocumentToWrapper).
> 
> Now.. to get the specific XalanNode* to use as context node for the 
> evaluate, I've tried using the mapNode method of the 
> XercesDocumentWrapper passing the DOMElement as a parameter.
> I got no errors but the result is NULL.
> 
> I don't get what am I doing wrong.
> 
> Can someone please help?

Can you please post some source code so we can see what you're doing. 
Preferably, a complete, _minimal_ sample.

Dave

Re: MapNode problems

Posted by David Bertoni <db...@apache.org>.
Antonio Scotti wrote:
> Here is what I do:
> 
> 
> void doXpath(xercesc_2_7::DOMElement* theElem, xercesc_2_7::DOMDocument* 
> theDoc)
> {
> 
> XALAN_CPP_NAMESPACE::XercesDocumentWrapper* theWrapper;
> XALAN_CPP_NAMESPACE::XercesDOMSupport* theDOMSupport;
> XALAN_CPP_NAMESPACE::XercesParserLiaison* theParserLiaison;
> const XALAN_CPP_NAMESPACE::XercesDOMWrapperParsedSource* theParsedSource;
> 
> 
> theDOMSupport = new XercesDOMSupport();
> theParserLiaison = new XercesParserLiaison(*theDOMSupport);
> theParserLiaison->setBuildWrapperNodes(true);
> theParserLiaison->setBuildMaps(true);
> 
> theDoc->normalize();
> 
> theParsedSource = new XercesDOMWrapperParsedSource(
>                                     theDoc,
>                                     *theParserLiaison,
>                                     *theDOMSupport);
> 
> theWrapper = 
> theParserLiaison->mapDocumentToWrapper(theParsedSource->getDocument());
> 

OK, the problem is you've never really built a wrapper around your 
instance of the Xerces-C DOM, so there's nothing to map.  Take a look at 
what the documentation for XercesParserLiaison::mapDocumentToWrapper() says:

/**
  * Map a pointer to a XalanDocument instance to its implementation
  * class pointer.  Normally, you should have no reason for doing
  * this.  The liaison will return a null pointer if it did not
  * create the instance passed.
...

So I don't understand why you're not getting a null pointer back from 
mapDocumentToWrapper(), unless there's more code that you're not showing.

> 
> XalanNode* myXalanNode = theWrapper->mapNode(theElem);
> 
>  /* ..... */
> }
> 
> Everything seems to works fine, exept for that mapNode, which return 
> NULL (if I use it to map a node from xalanNode to DOMElement it goes well).

Are you doing XPath searches or XSLT transformation?  If it's the 
former, which is what I think you're doing, then you have no need for an 
instance of XercesDOMWrapperParsedSource.  Instead, take a look at 
XercesParserLiaison::createDocument():

/**
  * Create a XalanDocument proxy for an existing Xerces document.
  * The parser liaison owns the instance, and you must not delete
  * it.	The liaison will delete it when reset() is called, or the
  * liaison is destroyed.
  *
  * @param theXercesDocument The Xerces document.
  * @param threadSafe If true, read access to the tree will be 
thread-safe (implies buildWrapper == true).
  * @param buildWrapper If true, the entire wrapper structure is built.
  * @param buildMaps If true, the map of Xerces to Xalan nodes is always 
built.
  * @return a pointer to a new XalanDocument-derived instance.
  */
XalanDocument*
createDocument(
	const DOMDocument_Type*	theXercesDocument,
	bool			threadSafe,
	bool			buildWrapper,
	bool			buildMaps = false);

You should use this function to create a wrapper for your Xerces-C DOM 
instance, making sure you pass in true for the buildWrapper and 
buildMaps parameters.

I think we need to write a sample program that illustrates this stuff. 
People are always asking about it, and it's not as obvious as it could 
be, that's for sure.

Dave

Re: MapNode problems

Posted by Antonio Scotti <as...@mbigroup.it>.
Here is what I do:


void doXpath(xercesc_2_7::DOMElement* theElem, xercesc_2_7::DOMDocument* 
theDoc)
{

XALAN_CPP_NAMESPACE::XercesDocumentWrapper* theWrapper;
XALAN_CPP_NAMESPACE::XercesDOMSupport* theDOMSupport;
XALAN_CPP_NAMESPACE::XercesParserLiaison* theParserLiaison;
const XALAN_CPP_NAMESPACE::XercesDOMWrapperParsedSource* theParsedSource;


theDOMSupport = new XercesDOMSupport();
theParserLiaison = new XercesParserLiaison(*theDOMSupport);
theParserLiaison->setBuildWrapperNodes(true);
theParserLiaison->setBuildMaps(true);

theDoc->normalize();

theParsedSource = new XercesDOMWrapperParsedSource(
                                     theDoc,
                                     *theParserLiaison,
                                     *theDOMSupport);

theWrapper = 
theParserLiaison->mapDocumentToWrapper(theParsedSource->getDocument());


XalanNode* myXalanNode = theWrapper->mapNode(theElem);

  /* ..... */
}

Everything seems to works fine, exept for that mapNode, which return 
NULL (if I use it to map a node from xalanNode to DOMElement it goes well).

Any clue?

Thanks in advance.



David Bertoni wrote:
> Antonio Scotti wrote:
> 
>> Hi! I've a problem using a XercesDocumentWrapper.
>>
>> I've a Xerces DOMDocument and I'd like to evaluate an xpath expression 
>> on a specific DOMElement.
>>
>> What I've done is to build a XercesDOMWrapperParsedSource (using the 
>> DOMElement, a XercesParserLiaison and a XercesDOMSupport).
>>
>> Then I got a XercesDocumentWrapper from the XercesParserLiaison (using 
>> mapDocumentToWrapper).
>>
>> Now.. to get the specific XalanNode* to use as context node for the 
>> evaluate, I've tried using the mapNode method of the 
>> XercesDocumentWrapper passing the DOMElement as a parameter.
>> I got no errors but the result is NULL.
>>
>> I don't get what am I doing wrong.
>>
>> Can someone please help?
> 
> 
> Can you please post some source code so we can see what you're doing. 
> Preferably, a complete, _minimal_ sample.
> 
> Dave