Hello,

I am relatively new to Xalan and somehow it drives me mad. I need to apply an xPath to the pre-parsed XML document. The document is a Xerces DOMDocument instance.

I read some postings on how to do that, but none of them worked. I will try to summerize my efforts below:

I saw a post from Joerg Seidler: http://marc.theaimsgroup.com/?l=xalan-c-users&m=108385669500218&w=2
and tried to do it in similar way, but with no luck.

My system configuration is:
Xerces-C 2.7.0
Xalan-C 1.10

May be I forgot some initialization or anything else.  Below are my explanations:
1. Assume that Xerces-C and XPathEvaluator initializations succeeded. And I have successfully parsed an XML document and have a DOMDocument instance pointer to which I need xPath to be applied. xPath _expression_ was successfully tested for this document with XMLSpy and Oxygen XML Editors (internally uses Xerces-J and Xalan-J). And the selection always delivered the desired node. I extensively use namespaces in my document and have my own namespace defined as default namespace. I know that xPath 1.0 does not support default namespaces that's why I also write a prefiexed xPath to the desired element.


My code looks as follows:


//xtcxsl, xtcxml are defined as follows:
/*
#ifdef XERCES_CPP_NAMESPACE
    namespace xtcxml=XERCES_CPP_NAMESPACE;
#else
    #define xtcxml
#endif   

#ifdef XALAN_CPP_NAMESPACE
    namespace xtcxsl=XALAN_CPP_NAMESPACE;
#else
    #define xtcxsl
#endif

*/


//assume that xPath is defined upon as XMLCh* or char*

xtcxsl::XMLSupportInit        xmlSupportInit;

xtcxsl::XercesDOMSupport     dom_support;
xtcxsl::XercesParserLiaison     parser_liaison(dom_support);

parser_liaison.setBuildWrapperNodes(true);
parser_liaison.setBuildMaps(true);

xtcxsl::XercesDOMWrapperParsedSource xSource(pDoc, parser_liaison, dom_support); //xtcxml::DOMDocument* pDoc is defined upon.

xtcxsl::XalanDocument& xeDoc     = *xSource.getDocument();
xtcxsl::XalanElement* ns_node    = xeDoc.getDocumentElement();

xtcxsl::XPathEvaluator    evaluator;

xtcxsl::NodeRefList result;
//resulting list has no elements
evaluator.selectNodeList(result, dom_support, ns_node, xPath, ns_node);
//node pointer is NULL
xtcxsl::XalanNode* node=evaluator.selectSingleNode(dom_support, ns_node, xPath, ns_node);




Using command line sample SimpleXPathAPI with the sampe xml document and xPath returns a valid node.


Can someone point me to what is wrong?


Many thanks!
--
Ovanes Markarian



Reply via email to