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 Manoj Kumar Chitlangia <ma...@ug.iiita.ac.in> on 2006/04/29 20:22:39 UTC
XalanDocument and DOMDocument Interchange
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);
XalanNode* result = evaluator.selectSingleNode(
dom_support_,
xalan_document_,
XalanDOMString(xpath).c_str(),
prefix_resolver);
XercesParserLiaison xerces_parser_liaison;
XercesDocumentWrapper *document_wrapper =
xerces_parser_liaison.mapDocumentToWrapper(xerces_parser_liaison.createDocument(dom_document_,
true, true, true));
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);
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)
Please tell me how should I go about to get a DOMNode out of the
XalanNode* result.
Thanks,
-Manoj
Re: XalanDocument and DOMDocument Interchange
Posted by Shalmi <sh...@gmail.com>.
David Bertoni wrote:
>
> 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);
> }
>
Hi,
In the above piece of code if Foo has to return XalanDocument then how can
it be achieved? I mean "theParserLiaison" has the ownership of XalanDocument
as per documentation. So once i return for the Foo function
"theParserLiaison" will go out of scope destroying XalanDocument whihc it
created.So what can be done in that case?
--
View this message in context: http://www.nabble.com/XalanDocument-and-DOMDocument-Interchange-tf1530799.html#a12814910
Sent from the Xalan - C - Users mailing list archive at Nabble.com.
Re: XalanDocument and DOMDocument Interchange
Posted by David Bertoni <db...@apache.org>.
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
>
>
>
>