Manoj Kumar Chitlangia wrote:
Hi,
I have the following declarations:
xalanc_1_10::XalanDocument *xalan_document;
xercesc_2_7::DOMDocument *dom_document_;
I have these statements afterwards to initialize these:
xalan_document = parser_liaison_.parseXMLStream(input_source);
This creates an instance of Xalan-C's default source tree implementation
from the input source.
XalanNode* result = evaluator.selectSingleNode(
dom_support_,
xalan_document_,
XalanDOMString(xpath).c_str(),
prefix_resolver);
Now you've selected a node from that document.
XercesParserLiaison xerces_parser_liaison;
XercesDocumentWrapper *document_wrapper =
xerces_parser_liaison.mapDocumentToWrapper(xerces_parser_liaison.createDocument(dom_document_,
true, true, true));
I have no idea what you're trying to attempt here. You're creating
another instance of a Xalan-C source tree, by wrapping what I suppose is
an instance of Xerces-C's DOMDocument, but you've not shown any code
related to create the document.
I want to get a DOMNode out of the XalanNode* result, but going by the
following method I get the Exception WRONG_DOCUMENT_ERR
const DOMNode *dom_node = (const DOMNode*)document_wrapper->mapNode(result);
At this point, result is a XalanNode from a XalanDocument which you
created in the call to parser_liaison_.parseXMLStream(). They are two
entirely different XalanDocument instances, so you cannot expect to map
a node from one document to another.
since result if owned by xalan_document but the XercesDocumentWrapper was
created for dom_document which is a DOMDocument.
Statements like these give null:
XercesDocumentWrapper *document_wrapper =
xerces_parser_liaison.mapDocumentToWrapper(xalan_document)
As expected, because that XalanDocument instance is not a wrapper for a
Xerces-C DOMDocument instance.
Please tell me how should I go about to get a DOMNode out of the
XalanNode* result.
You have to _start_ with an instance of Xerces-C's DOMDocument, and wrap
it for use in Xalan-C:
const xercesc_2_7::DOMNode*
foo(
xercesc_2_7::DOMDocument *dom_document_,
const XMLCh* xpath)
{
XALAN_USING_XALAN(XalanDOMString)
XALAN_USING_XALAN(XalanDocument)
XALAN_USING_XALAN(XalanElement)
XALAN_USING_XALAN(XalanNode)
XALAN_USING_XALAN(XercesDOMSupport)
XALAN_USING_XALAN(XercesParserLiaison)
XALAN_USING_XALAN(XPathEvaluator)
XALAN_USING_XALAN(ElementPrefixResolverProxy)
XALAN_USING_XALAN(XercesDocumentWrapper)
XercesDOMSupport theDOMSupport;
XercesParserLiaison theParserLiaison(theDOMSupport);
XalanDocument* theDocument =
theParserLiaison.createDocument(
dom_document_,
true,
true,
true,
true);
XPathEvaluator theEvaluator;
const XalanElement* const theRootElement =
theDocument.getDocumentElement();
ElementPrefixResolverProxy thePrefixResolver(theRootElement);
XalanNode* const theNode =
theEvaluator.selectSingleNode(
theDOMSupport,
theDocument,
XalanDOMString(xpath).c_str(),
prefix_resolver);
XercesDocumentWrapper* const theWrapper =
theParserLiaison.mapDocumentToWrapper(theDocument);
return theWrapper->mapNode(theNode);
}
Thanks,
-Manoj