o***@t-online.de
2005-11-17 09:41:12 UTC
<font style="font-family: arial,helvetica,sans-serif;"
size="2">Hello,<br /><br />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.<br /><br />I read some
postings on how to do that, but none of them worked. I will try to
summerize my efforts below:<br /><br />I saw a post from Joerg Seidler:
http://marc.theaimsgroup.com/?l=xalan-c-users&m=108385669500218&w=2<br
/>and tried to do it in similar way, but with no luck.<br /><br />My
system configuration is:<br />Xerces-C 2.7.0<br />Xalan-C 1.10<br /><br
/>May be I forgot some initialization or anything else. Below are my
explanations:<br />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.<br /><br /><br />My code looks as follows:<br /><br
/><br /><font size="2" style="font-family: courier
new,courier,monospace;">//xtcxsl, xtcxml are defined as follows: <br
/>/*<br />#ifdef XERCES_CPP_NAMESPACE<br /> namespace
xtcxml=XERCES_CPP_NAMESPACE;<br />#else<br /> #define xtcxml<br
/>#endif <br /><br />#ifdef XALAN_CPP_NAMESPACE<br /> namespace
xtcxsl=XALAN_CPP_NAMESPACE;<br />#else<br /> #define xtcxsl<br
/>#endif<br /><br />*/<br /><br /><br />//assume that xPath is defined
upon as XMLCh* or char*<br /><br />xtcxsl::XMLSupportInit
xmlSupportInit;<br /><br />xtcxsl::XercesDOMSupport dom_support;<br
/>xtcxsl::XercesParserLiaison parser_liaison(dom_support);<br /><br
/>parser_liaison.setBuildWrapperNodes(true);<br
/>parser_liaison.setBuildMaps(true);<br /><br
/>xtcxsl::XercesDOMWrapperParsedSource xSource(pDoc, parser_liaison,
dom_support); //xtcxml::DOMDocument* pDoc is defined upon.<br /><br
/>xtcxsl::XalanDocument& xeDoc = *xSource.getDocument();<br
/>xtcxsl::XalanElement* ns_node = xeDoc.getDocumentElement();<br
/><br />xtcxsl::XPathEvaluator evaluator;<br /><br
/>xtcxsl::NodeRefList result;<br />//resulting list has no elements<br
/>evaluator.selectNodeList(result, dom_support, ns_node, xPath,
ns_node);<br />//node pointer is NULL<br />xtcxsl::XalanNode*
node=evaluator.selectSingleNode(dom_support, ns_node, xPath,
ns_node);</font><br /><br /><br /><br />Using command line sample
SimpleXPathAPI with the sampe xml document and xPath returns a valid
node.<br /><br /><br />Can someone point me to what is wrong?<br /><br
/><br />Many thanks!<br />-- <br />Ovanes Markarian<br />
<br />
<br /><br />
</font>
size="2">Hello,<br /><br />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.<br /><br />I read some
postings on how to do that, but none of them worked. I will try to
summerize my efforts below:<br /><br />I saw a post from Joerg Seidler:
http://marc.theaimsgroup.com/?l=xalan-c-users&m=108385669500218&w=2<br
/>and tried to do it in similar way, but with no luck.<br /><br />My
system configuration is:<br />Xerces-C 2.7.0<br />Xalan-C 1.10<br /><br
/>May be I forgot some initialization or anything else. Below are my
explanations:<br />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.<br /><br /><br />My code looks as follows:<br /><br
/><br /><font size="2" style="font-family: courier
new,courier,monospace;">//xtcxsl, xtcxml are defined as follows: <br
/>/*<br />#ifdef XERCES_CPP_NAMESPACE<br /> namespace
xtcxml=XERCES_CPP_NAMESPACE;<br />#else<br /> #define xtcxml<br
/>#endif <br /><br />#ifdef XALAN_CPP_NAMESPACE<br /> namespace
xtcxsl=XALAN_CPP_NAMESPACE;<br />#else<br /> #define xtcxsl<br
/>#endif<br /><br />*/<br /><br /><br />//assume that xPath is defined
upon as XMLCh* or char*<br /><br />xtcxsl::XMLSupportInit
xmlSupportInit;<br /><br />xtcxsl::XercesDOMSupport dom_support;<br
/>xtcxsl::XercesParserLiaison parser_liaison(dom_support);<br /><br
/>parser_liaison.setBuildWrapperNodes(true);<br
/>parser_liaison.setBuildMaps(true);<br /><br
/>xtcxsl::XercesDOMWrapperParsedSource xSource(pDoc, parser_liaison,
dom_support); //xtcxml::DOMDocument* pDoc is defined upon.<br /><br
/>xtcxsl::XalanDocument& xeDoc = *xSource.getDocument();<br
/>xtcxsl::XalanElement* ns_node = xeDoc.getDocumentElement();<br
/><br />xtcxsl::XPathEvaluator evaluator;<br /><br
/>xtcxsl::NodeRefList result;<br />//resulting list has no elements<br
/>evaluator.selectNodeList(result, dom_support, ns_node, xPath,
ns_node);<br />//node pointer is NULL<br />xtcxsl::XalanNode*
node=evaluator.selectSingleNode(dom_support, ns_node, xPath,
ns_node);</font><br /><br /><br /><br />Using command line sample
SimpleXPathAPI with the sampe xml document and xPath returns a valid
node.<br /><br /><br />Can someone point me to what is wrong?<br /><br
/><br />Many thanks!<br />-- <br />Ovanes Markarian<br />
<br />
<br /><br />
</font>