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