David, thanks for your answer. The sample code and text documents are at work. What I can remember until now is that I stepped into the xPath evaluation function and set breakpoint for the namespace resolution. Somehow the default resolver used by Xalan always delivered null for the prefix. But my root element definitely has some specified namespaces.
A possible sample document could be the following: <root xmlns="http://my_unique_url_1" xmlns:tcs="http://my_unique_url_1" xmlns:cf="http://my_unique_url_2" xmlns:gen="http://my_unique_url_3" xmlns:xsi="schema-default-instance-which-I-currently-do-not-remember" xmlns:schemaLocation="http://my_unique_url_1 ./schema1.xsd etc..." att1="some text" att2="some text2"> <sub1 tcs:name="state1"> <cf:sub11 tcs:id="123"/> <cf:sub11 tcs:id="1234"/> </sub1> </root> xPath expression is: /tcs:root/tcs:sub1/cf:[EMAIL PROTECTED]:id='123'] This is fine with your sample. But if I parse it with a non-validating Xerces-C 2.7.0 parser and pass the DOM as described below I receive NULL-Pointer. Many Thanks, -- Ovanes Markarian -----Original Message----- Date: Thu, 17 Nov 2005 20:27:22 +0100 Subject: Re: Applying xPath to Xerces DOMDocument fails From: David Bertoni To: xalan-c-users@xml.apache.org [EMAIL PROTECTED] wrote: > 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: > ... > > Using command line sample SimpleXPathAPI with the sampe xml document and > xPath returns a valid node. > > > Can someone point me to what is wrong? > It's hard to say without seeing some actual data. Can you post a small sample document with namespaces, and the XPath expression you're using? You might also try just modifying the SimpleXPathAPI samples program to use the XercesDOMSupport and XercesParserLiaison classes, instead of writing your own code. That might help determine if the problem is in your code, your input data, or a bug in Xalan-C++.