Title: How to use XPathAPI.selectNodeIternator when namespace is used?

Hi,

I did post this question to xalan-j-user but I got no response.

Could someone tell me what changes to ApplyXPath.java example program (version 2.2 D14) is required when namespace is used?

For example, given an XML named test.xml:
<?xml version="1.0" encoding="UTF-8"?>
<root>
   ...
</root>

This test.xml works fine with the ApplyXPath.java sample program.  We could run it with the command:
java ApplyXPath test.xml /root
and will get everything as <output><root> ... </root></output>

However, if the namespace is used and declared, for example, as:
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns=" <http://www.xxx.com/ns>"
xmlns:xsi=" <http://www.w3.org/2001/XMLSchema-instance>"
xsi:schemaLocation=" <http://www.xxx.com/ns> test.xsd">
   ...
</root>

In this case the ApplyXPath will not be able to extract the nodeIternator 'root' and it therefore returns null.  The output of the ApplyXPath will then be

<output></output>

I understand that if I modify the ApplyXPath program and change the line setNamespaceAware to
dfactory.setNamespaceAware(false),
then the XPathApi.selectNodeIternator(doc, xpath) will then return a correct answer.

What should we do if we do need the DocumentBuilderFactory.setNamespaceAware(true)?  What changes are required to make the ApplyXPath.java?

Thanks
Philip

Reply via email to